> // Java version -----------------------------------
> public String getName()
> {
> // Doesn't work! What's the equivalent syntax?
> return getEntry<String,MyStringType>("name");
return this.<String,MyStringType>getEntry("name");
> }
>
[quoted text clipped - 4 lines]
> // Doesn't work! What's the equivalent syntax?
> setEntry<String,MyStringType>("name",value);
return this.<String,MyStringType>setEntry("name",value);
> }
>
[quoted text clipped - 16 lines]
> ((TBase)entries.get(key))).setValue(value);
> }
But all this won't work together in Java, because of erasure...
I think you need something like this:
public class YourCSharpPort {
public String getName() {
return getEntry("name", MyStringType.class);
}
public void setName(String value) {
setEntry("name", MyStringType.class, value);
}
Map<String, Object> entries;
protected <T, TBase extends MyBaseType<T>>
T getEntry(
String key, Class<TBase> typeOfTBase) {
TBase holder = typeOfTBase.cast(entries.get(key));
return holder != null ? holder.getValue() : null;
}
protected <T, TBase extends MyBaseType<T>>
void setEntry(
String key, Class<TBase> typeOfTBase,
T value) {
TBase holder = typeOfTBase.cast(entries.get(key));
if (holder == null && !entries.containsKey(key))
entries.put(key, holder = newInstanceOf(typeOfTBase));
holder.setValue(value);
}
protected <T> T newInstanceOf(Class<T> typeOfT) {
try {
return typeOfT.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
HTH,
piotr
z-man - 01 Oct 2006 23:54 GMT
>> // Java version -----------------------------------
>> public String getName()
[quoted text clipped - 83 lines]
> HTH,
> piotr
Many thanks Piotr, I'll get a try of it!