#Doubt related Interface implementation

23 messages · Page 1 of 1 (latest)

bronze holly
#

if an interface has multiple abstract functions , can we use annonymous inner class to implement only one of them

copper quailBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

plush hemlock
#

if u want a class that can say "im an instance of this interface" then it must have implemented all abstract methods

bronze holly
#

ohh

plush hemlock
#

u cant say "ICanJump" and then only implement one of the two methods ICanJump demands

bronze holly
#

that makes sense

#

so I would have to implement both of them

#

thanks

halcyon turret
#

Which means you can't use a lambda or method reference, since those only apply to 'functional interfaces' that have a singl abstract method.

halcyon turret
#

But you can implement both with an anonymous inner class.

bronze holly
#

hmm

halcyon turret
#

It's just not nearly as syntactically convenient.

bronze holly
#

yeah I'd rather make a class that implements the interface and then make an instance of that class

halcyon turret
#

Yeap.

bronze holly
halcyon turret
#

No. I meant that you can ignore the non-abstract methods... you can have as many of them as you like (well, up to the bytecode format limit)

plush hemlock
#

concrete methods are fine

#

but in a interface that means default methods

bronze holly
#

oh yeah right

#

thanks