Skip to content

Tag: interface

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 …

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…

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&…