简体   繁体   English

具有不同类型的Google App Engine数据存储区实体属性

[英]Google App Engine Datastore Entity properties with different types

How do I create a property that can accept both a ArrayList<Integer> and ArrayList<String> ? 如何创建可以同时接受ArrayList<Integer>ArrayList<String>的属性?

I tried setting it as ArrayList<Object> but it doesn't accept either parameters. 我尝试将其设置为ArrayList<Object>但是它不接受任何一个参数。

You can use a Low-level Datastore API to set the same property to either ArrayList<Integer> (which will be stored and retrieved as ArrayList<Long> , by the way) or ArrayList<String> . 您可以使用低级数据存储区API将相同的属性设置为ArrayList<Integer> (将以ArrayList<Long>的方式存储和检索)或ArrayList<String> You should remember, however, to type-check when you retrieve the value of this property (casting from ArrayList<Long> to ArrayList<String> or vice versa is not possible), and you will have to write this code yourself. 但是,您应该记住,在检索此属性的值时进行类型检查(不可能从ArrayList<Long>广播到ArrayList<String> ,反之亦然),并且您必须自己编写此代码。

In general, this is not a good practice. 通常,这不是一个好习惯。 Strong typing is an advantage of Java. 强类型化是Java的优势。 Use it. 用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM