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

后端 未结 7 1104
感情败类
感情败类 2020-12-12 06:29

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

All the po

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 07:21

    Don't fully understand what you are trying to achieve. Did you mean this?

    private static long  countModel(Model model)
    {
        return model.count();
    }
    
    renderArgs.put("countryCount", countModel(country));
    

    EDIT: If count is a static method, it has nothing to do with model. The static method is not inherited. So all you have to do is to call it directly,

    renderArgs.put("countryCount", Country.count());
    

提交回复
热议问题