js-to-java icon indicating copy to clipboard operation
js-to-java copied to clipboard

如何对 Map key做类型转换

Open hxykjc opened this issue 7 years ago • 1 comments

如何表达 java 中 Map Map<Integer, Object> 或是更复杂的 Map<Object, Object>

hxykjc avatar May 16 '18 04:05 hxykjc

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' } } } }

TheNorthMemory avatar Aug 19 '18 11:08 TheNorthMemory