Passing a class ("Country.class") as an argument in Java

Posted by Coronatus on Stack Overflow See other posts from Stack Overflow or by Coronatus
Published on 2010-05-22T20:08:28Z Indexed on 2010/05/22 20:10 UTC
Read the original article Hit count: 154

Filed under:
|

I'm trying to make a method that takes an argument of Country.class, User.class etc, and returns argument.count().

All the possible classes that I would give to this method extend from Model and have the method count().

My code:

private static long <T> countModel(Model<T> clazz)
{
    return clazz.count();
}

Called by:

renderArgs.put("countryCount", countModel(Country.class));

However this just doesn't work at all.

How do I do this, please?

© Stack Overflow or respective owner

Related posts about java

Related posts about type-casting