Why no static methods in Interfaces, but static fields and inner classes OK? [pre-Java8] [duplicate]

An official proposal has been made to allow static methods in interfaces in Java 7. This proposal is being made under Project Coin. My personal opinion is that it’s a great idea. There is no technical difficulty in implementation, and it’s a very logical, reasonable thing to do. There are several proposals in Project Coin … Read more

What is a capture conversion in Java and can anyone give me examples?

Capture conversion was designed to make wildcards (in generics), ? useful. Suppose we have the following class: public interface Test<T> { public void shout(T whatever); public T repeatPreviousShout(); } and somewhere on our code we have, public static void instantTest(Test<?> test) { System.out.println(test.repeatPreviousShout()); } Because test is not a raw Test and since repeatPreviousShout() in … Read more

How to create a class literal of a known type: Class

You can always cast to what you need, like this return (Class<List<String>>) new ArrayList<String>().getClass(); or return (Class<List<String>>) Collections.<String>emptyList().getClass(); But I assume that’s not what you are after. Well it works, with a warning, but it isn’t exactly “beautiful”. I just found this Why is there no class literal for wildcard parameterized types? Because a wildcard … Read more