可以和通过代码中typedef FooBar Bar;
的表达式获取类型FooBarFoo::Bar
#include <typeinfo>
#include <iostream>
class FooBar {};
class FooBat {};
class Foo
{
public:
typedef FooBar Bar;
typedef FooBat Bat;
};
int main()
{
if( typeid(Foo::Bar) == typeid(FooBar) &&
typeid(Foo::Bat) == typeid(FooBat) )
std::cout << "All is well." << std::endl;
}
被翻译成Java?
对类型的间接引用的 Java 等价物是什么?
STL 和 boost 中充满了诸如
typedef T value_type;
typedef T* iterator;
我想知道Java是否支持类似的通用编程习惯。即使无法在编译时完成类型间接,我仍然对答案感兴趣。
编辑 这个问题(如何在 Java 中进行非平凡的泛型编程)并没有引起那些精通 Java 的人的兴趣。我现在添加“C++”作为标签。