Horse Voice Horse Voice - 11 months ago 46
Java Question

Odd method call in java using a dot operator to access a generic list

I came across some advanced java code (advanced for me :) ) I need help understanding.

In a class there is a nested class as below:

private final class CoverageCRUDaoCallable implements
private final long oid;
private final long sourceContextId;

private CoverageCRUDaoCallable(long oid, long sourceContextId)
this.oid = oid;
this.sourceContextId = sourceContextId;

public List<ClientCoverageCRU> call() throws Exception
return coverageCRUDao.getCoverageCRUData(oid, sourceContextId);

Later in the outer class, there is an instance of the callable class being created.
I have no idea what this is:

ConnectionHelper.<List<ClientCoverageCRU>> tryExecute(coverageCRUDaoCallable);

It doesn't look like java syntax to me. Could you please elaborate what's going on in this cryptic syntax? You can see it being used below in the code excerpt.

CoverageCRUDaoCallable coverageCRUDaoCallable = new CoverageCRUDaoCallable(
dalClient.getOid(), sourceContextId);

// use Connection helper to make coverageCRUDao call.
List<ClientCoverageCRU> coverageCRUList = ConnectionHelper
.<List<ClientCoverageCRU>> tryExecute(coverageCRUDaoCallable);

added the ConnectionHelper class.

public class ConnectionHelper<T>
private static final Logger logger =

private static final int CONNECTION_RETRIES = 3;

private static final int MIN_TIMEOUT = 100;

public static <T> T tryExecute(Callable<T> command)
T returnValue = null;
long delay = 0;

for (int retry = 0; retry < CONNECTION_RETRIES; retry++)
// Sleep before retry

if (retry != 0)
{"Connection retry #"+ retry);

// make the actual connection call
returnValue =;

catch (Exception e)
Throwable cause = e.getCause();
if (retry == CONNECTION_RETRIES - 1)
{"Connection retries have exhausted. Not trying "
+ "to connect any more.");

throw new RuntimeException(cause);

// Delay increased exponentially with every retry.
delay = (long) (MIN_TIMEOUT * Math.pow(2, retry));

String origCause = ExceptionUtils.getRootCauseMessage(e);"Connection retry #" + (retry + 1)
+ " scheduled in " + delay + " msec due to "
+ origCause);
+ origCause);
return returnValue;

Answer Source

You more often think of classes as being generic (also known as parametric polymorphism), but methods can be generic too. A common example is Arrays.asList.

Most of the time, you don't have to use the syntax with angle brackets <...>, even when you're invoking a generic method, because this is the one place in which the Java compiler is actually capable of doing basic type inference in some circumstances. For example, the snippet given in the Arrays.asList documentation omits the type:

List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");

But it's equivalent to this version in which the generic type is given explicitly:

List<String> stooges = Arrays.<String>asList("Larry", "Moe", "Curly");