English 中文(简体)
界定类别申报的类型?
原标题:Defining Types on Class declaration?
  • 时间:2012-01-11 16:09:13
  •  标签:
  • java
  • android

对贾瓦来说,情况相对较新,我最近走过了我以前从未见过的yn。

public class loadSomeData extends AsyncTask<String, Integer, String>{ etc..}

The part that confuses me is the stuff between the <> brackets. I understand what each of the Types are used for in this class, but why declare them in the class declaration?

更具体地说,这一点是什么:<DataType>,在 Java呼吁,以便我研究?

谢谢。

最佳回答

http://en.wikipedia.org/wiki/Generics_in_Java"rel=“nofollow” in Java。

In brief, a collection class (or any class, really) may declare a parameterized type using that syntax so that users of the class can ensure that only objects of the same type will be stored in its collections (or otherwise operated on by it).

在非专利之前,在清单等收集方面没有任何类型安全:

List numbers = new ArrayList();
numbers.add(Integer.valueOf(123)); // OK
numbers.add("foo"); // Uh-oh!

但现在,你可以确保,只有你宣布的类型才能增加:

List<Number> numbers = new ArrayList<Number>();
numbers.add(Integer.valueOf(123)); // OK
numbers.add("foo"); // Compile-time error!
问题回答

你们正在看到 Java的基因特征。 http://docs.oracle.com/javase/tutorial/java/generics/index.html” rel=“nofollow” http://docs.oracle.com/javase/tutorial/java/generics/index.html。

The <DataType> structure is referred to as category paramaters of the 缩略语 Java类。 这意味着在其运作中可以使用不同的通用类别。 见上文链接。





相关问题
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 ...