Method createBuilderFactory
in javax.json
needs argument of type Map<String, ?>
Generally, we have map with like Map<String, String>
(some other data types in place of String
)
But I didn't understand what does ?
stands for. And in order to pass argument of type Map<String, ?>
, how I should define the map.
Can someone please help me to understand this better?
In Java generics the ?
stands for wildcard, which represent any object.
If you create a method that takes Map<String, ?>
you are saying that you expect a Map
that maps from String
keys to any possible object values:
public static void main(String[] args) {
Map<String, Object> map1 = null;
Map<String, String> map2 = null;
test(map1);
test(map2);
}
private static void test(Map<String, ?> settings) {}
I had difficulties when I need to pass Map<String, ?>
to my function, which was accepting Map<String, Object>
. And this cut it:
Map<String, ?> mapQuestion = ...
mapObject = (Map<String, Object>)mapQuestion;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With