如何在Java中将getClass与泛型一起使用 [英] How to use getClass with Generics in java

查看:79
本文介绍了如何在Java中将getClass与泛型一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我得到了这个,我不知道该怎么办,我在阳光下搜寻,但是对此没有答案

我想编写一个通用方法以用于每种类型,因此当我编写此方法时,它不适用于实际类型.所以谁能告诉我如何使用类型为"T"的"getClass"

这是方法

Hi every body, i got this one i don''t know what to do, i search in the sun but don''t have the answer about this

I want to write a generic method to use with every type, so when i write this method, it didn''t work with the real type. So could anyone show me how to use "getClass" with type "T"

This is the method

public <T> T GetByID(int id) {
        return (T) m_Session.get(getClass(), id);
}

推荐答案

反映泛型由伊恩·罗伯森(Ian Robertson) [ ^ ]

您可能需要阅读.
Reflecting generics by Ian Robertson[^]

you might want to read that.


这篇关于如何在Java中将getClass与泛型一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆