简体   繁体   中英

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.

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". What type of parameter I need to pass into setParameterTypes method?

It asks for a list of specific Class objects. In this case a list of Class objects which represent classes which extends from the 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> Class<? extends DataType> variables.

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() .

A List<Class<?>> is a list of Class objects eg

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

A 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 CharSequence>> could be

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

The statement defines the type of each parameter that the FunctionEntry takes. Although, the way you typed it is not syntactically correct. The definition of setParameterTypes is

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 . For example, the classes OpssBoolean , OpssInteger and OpssDouble are subclasses of DataType in the Oracle API. 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:

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. So this method will return {OpssBoolean.class,OpssBoolean.class} for AND or OR functions.

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

It is asking you to pass a List<MyDataType> where

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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