#2828 How to map Java generics type to Fantom?

CretinHo Sat 1 May

You can see the example here:


It would be lucky for me if they use Java's Map type, because there is a Fantom Map type to map with it. The problem is they used their own Map type:

import org.apache.pivot.collections.Map;

I have no idea how to translate this:

public void startup(Display display, Map<String, String> properties)

to Fantom code.

Any attempts of mine always resulted in type mismatch error.

brian Sun 2 May

The simple answer is you don't. Java generics are erased, so when working with Java code thru the Java FFI you just work with them as unparameterized classes. For example:

using [java]java.util::HashMap 

map := HashMap()
map.put("key1", "val1")
map.put("key2", "val2")

Also look at the Interop class which provides utils to map b/w Fantom lists/maps and Java ones:

Login or Signup to reply.