Howdy, I am trying to understand this method signature:
public <K> Map<K, String> getMulti(Serializer<K> keySerializer, K... keys)
For the following code block:
public <K> Map<K, String> getMulti(Serializer<K> keySerializer, K... keys) {
MultigetSliceQuery<K, String, String> q = createMultigetSliceQuery(keyspace, keySerializer, serializer, serializer);
q.setColumnFamily(CF_NAME);
q.setKeys(keys);
q.setColumnNames(COLUMN_NAME);
QueryResult<Rows<K, String, String>> r = q.execute();
Rows<K, String, String> rows = r.get();
Map<K, String> ret = new HashMap<K, String>(keys.length);
for (K k : keys) {
HColumn<String, String> c = rows.getByKey(k).getColumnSlice().getColumnByName(COLUMN_NAME);
if (c != null && c.getValue() != null) {
ret.put(k, c.getValue());
}
}
return ret;
}
I am not sure what <K> in the method declaration represents, or what K... is suppose to mean. Can anyone shed some light on these?
The
Kis the type parameter of this method. It can be anything you want. E.g.Integer. In that case you need to visually (in your mind) substitute allK‘s in the method signature withIntegerto understand what it’s taking and returning. WithIntegerasK, the method will then behave as follows:The
...in turn is the varargs syntax. It allows you to pass zero-more arguments of or an array of the given type into the method. E.g.