能typedef FooBar Bar;
并在代码模拟C++ - 用Java
#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;
}
的访问类型FooBar的通过表达Foo::Bar
的typedef被翻译成Java?
对于类型的间接引用,Java的等价物是什么?
的STL和提升都充满了这样的代码
typedef T value_type;
typedef T* iterator;
我想知道的Java是否支持类似的泛型编程成语。 即使类型间接不能在编译时完成,我仍然对答案感兴趣。
编辑 这个问题(如何在Java中进行非平凡的泛型编程)没有得到那些熟悉Java的熟悉者的兴趣。我现在添加“C++”作为标签。
也许这会帮助http://stackoverflow.com/questions/1195206/is-there-a-java-equivalent-or-methodology-for-the-typedef-keyword-in-c – lawrencexu