• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Interface in java

Java 8 now has Default Methods, so I suppose an interface *could* have code. Vague question is vague.
 
Class interface?
user interface?
graphical user interface?

You need to provide some hints as to your "situation". Most of us are not very good at 20 questions
 
purbeast , HA

Interface is what you want to do. Implementation (class) is how you do it.

Unless you're in Java 8, where an interface may also tell you how to do it. [Worst] design decision in all of Java, yet. Well, that and Functional Interfaces, which make for some REALLY ugly lambdas.

No swearing in the technical forms, please -- Programming moderator Ken g6
 
Last edited by a moderator:
I refuse to use java 8 then.

Wait, multiple parents are now possible?

Yes and no. An interface can now supply a default implementation of a method, but it cannot maintain state in any way. So interfaces still can't contain instance variables. What these new Default Method interfaces can do, though, is also include some abstract methods that the concrete class must implement. A Default Method can use the abstract methods, so that lets you blur the lines of multiple inheritance a bit.

Personally, I think it's just fancy spaghetti code and/or a failed abstraction. It's a very poor composition/mix-in substitute that doesn't add much to the language other than cause confusion. These new interfaces were introduced to the language basically just to support the new Streams API.

Java feels dated. I don't understand the "write once, run anywhere" approach. Because of this, we're stuck with clunky compromises to maintain compatibility with ancient versions of Java that nobody uses. If composition and functional programming were actually important, they should be built into the language itself, rather than making them just some syntax sugar. Anders Helsjberg got it right, methinks.

So yea, a year ago, we could have ended the thread with reallyscrued's answer. Now, with Java 8, interfaces are needlessly "flexible."
 
I read an article and the reason that this new interface construct was added was because of Lambdas. I forget the full rational but without this construct, Lambdas would not be possible.
 
This, for the love of God.

Leave the kid alone. He doesn't yet realize that Google can do 99% of his homework. Actually, it's how I do a lot of things these days.

I can come up wit ha method to take remaining milliseconds and convert it to remaining years, months, days and hours .... or I can Google the solution and copy in paste it all in about 1 minute.

Anyways ... want ot know how to use interfaces in Java? Google it? Wikipeida probably even has examples.

Best common use for interfaces that we use at work frequently? Write an interface that interacts with an Oracle database. And for unit testing implement the same interface but use HSQLDB behind the scenes. Design the software so that it is easy to swap the implementations.
 
Leave the kid alone. He doesn't yet realize that Google can do 99% of his homework. Actually, it's how I do a lot of things these days.

Yes, I Google too. Sometimes I even post messages on forums. And then when people respond I engage with them in a hopefully intelligent discussion about my problem.
 
I read an article and the reason that this new interface construct was added was because of Lambdas. I forget the full rational but without this construct, Lambdas would not be possible.

So that's true, but it's not the complete truth. Functional Interfaces were the least intrusive way of introducing lambas to Java while maintaining backward compatibility all the way to Java of old. So basically, they ended up with a crappy, clunky implementation of lambda expression support. C# has it made! 🙂
 
Back
Top