[英]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.class
和AnotherDataTypeToUse.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. 例如,类OpssBoolean
, OpssInteger
和OpssDouble
是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.