js-to-java
js-to-java copied to clipboard
如何对 Map key做类型转换
如何表达 java 中 Map Map<Integer, Object> 或是更复杂的 Map<Object, Object>
refer to hessian.js#Java Generic Map
Map<Integer, Object>
util.inspect.defaultOptions.depth = 7
let i2oMap = java.Map(new Map([
[java.Integer(1), java('com.test.Object', { foo: 'bar' })]
]))
console.info('%O', i2oMap)
{ '$class': 'java.util.Map',
'$':
Map {
{ '$class': 'java.lang.Integer', '$': 1 } => { '$class': 'com.test.Object', '$': { foo: 'bar' } } } }
Map<Object, Object>
util.inspect.defaultOptions.depth = 7
let o2oMap = java.Map(new Map([
[java('com.test.Object', { bar: 'foo' }), java('com.test.Object', { foo: 'bar' })]
]))
console.info('%O', o2oMap)
{ '$class': 'java.util.Map',
'$':
Map {
{ '$class': 'com.test.Object', '$': { bar: 'foo' } } => { '$class': 'com.test.Object', '$': { foo: 'bar' } } } }