The following code doesn’t compile
import com.google.common.collect.LinkedHashMultimap;
public class Test {
public static void main(String[] args) {
LinkedHashMultimap<String, String> p = new LinkedHashMultimap<String, String>();
}
}
the error is: The constructor LinkedHashMultimap() is not visible
I have imported the google Java libraries, they are in the build path
and
LinkedHashMultimap<String, String> p;
alone doesn’t cause compile error… weird
LinkedHashMultimaphas no public constructors and the way to get an instance is by using the factory methodcreate. The reason for this is the loophole in Java Generics due to which type inference works only for methods and not for constructors. This means that instead of for exampleyou can write
With Java 7 the pressure has subsided due to the “diamond operator”.