简体   繁体   English

这是什么意思List &lt;Class <? extends DataType> &gt;?

[英]What does this mean List < Class <? extends DataType>>?

I ran into a below statement which expects aforementioned parameter type while reviewing oracle entitlement server API. 我在查看oracle权利服务器API时遇到了下面的语句,该语句期望上述参数类型。

FunctionEntry functionEntry = ...;
functionEntry.setParameterTypes(List<Class<? extends DataType>>);

I am having a hard time to understand what it is asking for. 我很难理解它的要求。 I only understand "? extends DataType". 我只了解“?extended DataType”。 What type of parameter I need to pass into setParameterTypes method? 我需要将哪种类型的参数传递给setParameterTypes方法?

It asks for a list of specific Class objects. 它要求特定的Class对象的列表。 In this case a list of Class objects which represent classes which extends from the DataType class. 在这种情况下,代表从DataType类扩展的Class对象的列表。 When you extends from this class like: 当您从此类扩展时,例如:

public class MySpecialDataType extends DataType
{
}

public class AnotherDataTypeToUse extends DataType
{
}

you can use the expressions MySpecialDataType.class and AnotherDataTypeToUse.class (something called "class literal") to get objects which can be assigned to Class<? extends DataType> 您可以使用表达式MySpecialDataType.classAnotherDataTypeToUse.class (称为“类文字”)来获取可以分配给Class<? extends DataType>对象Class<? extends DataType> Class<? extends DataType> variables. Class<? extends DataType>变量。

Class<MySpecialDataType> clazzOne = MySpecialDataType.class;
Class<AnotherDataTypeToUse> clazzTwo = AnotherDataTypeToUse.class;
Class<? extends DataType> baseClazz = clazzOne; // works
baseClazz = clazzTwo; // also works
List<Class<? extends DataType>> clazzes = new ArrayList<Class<? extends DataType>>();
clazzes.add(clazzOne);
clazzes.add(clazzTwo);

functionEntry.setParameterTypes(clazzes);

You might want to look at Arrays.asList() for the argument of setParameterTypes() . 您可能需要查看Arrays.asList()作为setParameterTypes()的参数。

A List<Class<?>> is a list of Class objects eg List<Class<?>>Class对象的列表,例如

Arrays.asList(String.class, Boolean.class, Pattern.class)`

A List<Class<? extends T>> List<Class<? extends T>> List<Class<? extends T>> is a list that can only contain the Class objects of T and its subclasses eg List<Class<? extends CharSequence>> List<Class<? extends T>>是一个列表,只能包含T及其子类的Class对象,例如List<Class<? extends CharSequence>> List<Class<? extends CharSequence>> could be List<Class<? extends CharSequence>>可能是

Arrays.asList(String.class, StringBuffer.class, StringBuilder.class, CharSequence.class)`

The statement defines the type of each parameter that the FunctionEntry takes. 该语句定义FunctionEntry接受的每个参数类型。 Although, the way you typed it is not syntactically correct. 虽然,您键入的方式在语法上不正确。 The definition of setParameterTypes is setParameterTypes的定义是

setParameterTypes(java.util.List<java.lang.Class<? extends DataType>> parameters)

So it is expecting a list of classes corresponding to the parameter types of the function you are defining, with the added requirement that the types must be subclasses of DataType . 因此,它期望一个与您要定义的函数的参数类型相对应的类列表,并增加了这些类型必须是DataType子类的要求。 For example, the classes OpssBoolean , OpssInteger and OpssDouble are subclasses of DataType in the Oracle API. 例如,类OpssBooleanOpssIntegerOpssDouble是Oracle API中DataType的子类。 So if you wanted to define a function in this API that takes an OpssBoolean as 1st parameter, an OpssInteger as 2nd parameter, and an OpssDouble as 3rd parameter, you define it this way: 因此,如果您想在此API中定义一个函数,该函数将OpssBoolean作为第一个参数,将OpssInteger作为第二个参数,并将OpssDouble作为第三个参数,则可以这样定义:

List<java.lang.Class<? extends DataType>> parameterTypes = Arrays.asList(
    OpssBoolean.class, OpssInteger.class, OpssDouble.class
);
functionEntry.setParameterTypes(parameterTypes);

It returns a list of input parameters. 它返回输入参数的列表。

Lets say, this function takes a variable number of input parameters, it will return the TYPES of minimum required inputs. 可以说,此函数采用可变数量的输入参数,它将返回最小所需输入的类型。 For example, logical functions AND and OR can take an unbound number of input parameters but require minimum 2 OpssBoolean type parameters. 例如,逻辑函数AND和OR可以接受无数个输入参数,但至少需要2个OpssBoolean类型参数。 So this method will return {OpssBoolean.class,OpssBoolean.class} for AND or OR functions. 因此,此方法将为AND或OR函数返回{OpssBoolean.class,OpssBoolean.class}。

它要求List中的对象应该扩展DataType

It is asking you to pass a List<MyDataType> where 它要求您传递一个List<MyDataType>其中

public class MyDataType extends DataType
{
    /* your data type stuff */
}

See here for details on DataType: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html 有关数据类型的详细信息,请参见此处: https : //docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

暂无
暂无

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

相关问题 什么课 <? extends ParentClass> 意思? - What does Class<? extends ParentClass> mean? 那是什么? 表示“格式”(列表 <? extends NameValuePair> ” - What does the ? mean in “format(List<? extends NameValuePair>” 列出什么 <JAXBElement<? extends SomeClassName> &gt;是什么意思? - What does List<JAXBElement<? extends SomeClassName>> mean? 这个Java语法是什么意思? (`类 <? extends ContactAccessor> clazz`) - What does this Java syntax mean? (`Class<? extends ContactAccessor> clazz`) 这个 Java 语法是什么意思? (`类<? extends E>克拉兹`) - What does this Java syntax mean? (` Class<? extends E> clazz`) 在 Java 的泛型类中,“T 扩展垃圾”是什么意思? - What does "T extends Junk" mean in a generic class in Java? “扩展JPanel”是什么意思? - What does “extends JPanel” mean? 做什么<t extends mean?< div><div id="text_translate"><p> 我见过如下所示的方法:</p><pre> protected &lt;T extends ABC&gt; T save( T Acd, boolean en) {</pre><p> 它有什么作用? 这些类型的方法声明在 Java 中称为什么?</p></div></t> - What does <T extends mean? 复杂泛型类型声明的解释。 什么类 <? extends Class<? extends Actor> []&gt;实际意味着什么? - Explanation for convoluted generic-type declaration. What does Class<? extends Class<? extends Actor>[]> actually mean? 使用“类”作为数据类型意味着什么? - What does it mean when one uses “class” as a datatype?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM