I'm trying to use the Datastax Java driver API for Cassandra DB, and I have a row object that has the function getList:
public <T> List<T> getList(String name,
Class<T> elementsClass)
Returns the value of column name as a list.
Parameters:
name - the name of the column to retrieve.
elementsClass - the class for the elements of the list to retrieve.
Returns:
the value of the ith column in this row as a list of elementsClass objects. If the value is NULL, an empty list is returned (note that Cassandra makes no difference between an empty list and column of type list that is not set).
My question is how do I actually use this? I don't know how to make a parameter of Class<T> elementsClass
type. In my case, the result should be a list of floats (based on the Cassandra schema that I'm using).
To get the List<Float>
, you can invoke the method using class literal - Float.class
:
List<Float> list = getList(someName, Float.class);
From JLS 15.8.2 - Class Literals:
A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void, followed by a
'.'
and the token class.The type of
C.class
, whereC
is the name of a class, interface, or array type (§4.3), isClass<C>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With