Skip to content
Advertisement

Tag: interface

What’s the differences between Go and Java about interface? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago. Improve this question Recently I’ve been asked a question which is, what’s the difference between Golang and Java about interface? I know there

Logging from default interface methods

Salut to all Java gurus! Since Java8 we can have default implementations in interfaces (yay!). However problem arises when you want to log from default method. I have a feeling that it is not wise to call .getLogger() every time I want to log something in a default method. Yes, one can define static variable in an interface – but

Can an interface method have a body?

I know that an interface is like a 100% pure abstract class. So, it can’t have method implementation in it. But, I saw a strange code. Can anyone explain it? Code Snippet: EDIT: My IDE is Intellij Idea 13.1. The project SDK is java 7 <1.7.0_25>. The IDE is not showing any compiler error. But, When I compile the code

Is there such a thing as a “local interface” in Java?

Java allows me to define local abstract classes, like in this example: For some reason, when I try to define a “local interface” instead of the local class, like this: Java complains that “The member interface Bar can only be defined inside a top-level class or interface”. Is there a reason for this? Or am I missing a mistake I

Can a normal Class implement multiple interfaces?

I know that multiple inheritances between Interfaces is possible, e.g.: But is it possible to have a regular Class inherit from multiple Interfaces like this: Answer A Java class can only extend one parent class. Multiple inheritance (extends) is not allowed. Interfaces are not classes, however, and a class can implement more than one interface. The parent interfaces are declared

How to implement enum with generics?

I have a generic interface like this: This interface has limited instances, hence it would be best to implement them as enum values. The problem is those instances have different type of values, so I tried the following approach but it does not compile: Any idea about this? Answer You can’t. Java doesn’t allow generic types on enum constants. They

Advertisement