Question

I'm working on a GWT project to implement indexeddb support for GWT. I wonder how could I pass the value of type 'any' from java to javascript (and vice-versa)? For example, this javascript method is from the ObjectStore specification:

IDBRequest add( in any value, in optional any key ) raises (IDBDatabaseException, DOMException);

(Basically what that method does is to add a pair of key & value to the database. Hence, the key and value can be any object, which explain why their type is any)

I tried to used generic type in Java to pass java value to the variables value and key, but it doesn't seem to work. It'd be great if you can provide an example code :)

Était-ce utile?

La solution 3

I convert those object into json, and pass it without any problem :)

Autres conseils

Just use a generic Java Object if you really want any type. Usually this is not really a good idea, but you did say you want any type, and the general Object encompasses that.

I don't know if it applies to your case because we lack that information, but you can always pass your values as Strings since it can represent pretty much anything (booleans, chars, ints, longs, floats, etc.). You just have to make sure they're valid and then you can parse/convert/cast them as you wish.

or hbtest's answer

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top