Reputation: 4591
I'm starting to use the Guava classes and stumbling about the missing constructors.
I have a method that gets a LinkedHashMultiset<String>
. How do I create a new argument in the method call?
class.method(LinkedHashMultiset.create());
makes the compiler complain that there is no method for class.method(LinkedHashMultiset<Object>)
.
And class.method((LinkedHashMultiset<String)LinkedHashMultiset.create())
fails due to an impossible cast.
Upvotes: 0
Views: 336
Reputation: 691765
As with any generic method. EIther the type is deduced by the compiler (type inference):
LinkedHashMultiset<String> set = LinkedHashMultiset.create();
or it's not, and you have to specify the type:
LinkedHashMultiset.<String>create()
Upvotes: 6
Reputation: 35437
One way is the following:
class.method(LinkedHashMultiset.<String>create());
One other is this:
Multiset<String> multiset = LinkedHashMultiset.create();
class.method(multiset);
Upvotes: 5