English 中文(简体)
我试图创建数组列表, 并尝试使用相同方法或实例的方法只存储字符串和整数对象, 但是我们也可以使用 General [ 已关闭] 来这样做 。
原标题:I try to create arraylist and try to store only string and integer object using equal or instance of method but can we do the same using Generic [closed]
问题回答

无法 。 普通类依赖继承来创建代码类型安全。 您需要一个普通的超级类 。 如果您不想写入自己的收藏, 您可能会考虑创建您自己的类, 该类可以摘要描述您想要添加的内容的概念。 列表中的字符串和整数代表后缀( 仅举一例 ) 。 然后您将创建一个类 < code> 后缀 , 要么持有字符串,要么使用整数, 提供您正在查找的这些对象上的共同行为 。 这样您的列表将接受 < code> 后缀 < /code > 对象 。

首先,这个混合阵列员的目的是什么?你怎么命名它?反正,回到你的问题,答案是我们可以(以某种方式),但它不可取IMHO。

class Holder {
    String strValue;
    Integer intValue;
}
List<Holder> alist = new ArrayList<Holder>();

你得到这个想法。 ; ))





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签