在Java中实现typedef [英] Implement typedef in Java
问题描述
我有一个类型Time32,在泛型中用作工作< Time32>
所以我创建了一个类Time32。
我还必须实现
I have a type Time32 that is used in generics as Work<Time32>
so i made a class Time32.
I also have to implement
typedef UInt(5) Time32
这里UInt表示unsigned int。 Java没有unsigned int,所以我创建了自己的类。
Here UInt means the unsigned int. Java doesn't have unsigned int, so i made my own class.
public class UInt
{
private final int size;
public UInt(int x)
{
this.size=x;
}
public int getSize()
{
return size;
}
}
但我不明白我是如何实现的java中的typedef。请帮忙。谢谢。
But i don't understand how i can implement the typedef in java. Please help. Thanks.
我需要保留UInt类,因为我有一些其他变量将使用Uint,如 UInt(20)Load
或 UInt(10)强制
I need to keep the UInt class as i have some other variables that will use the Uint like UInt(20) Load
or UInt(10) Force
推荐答案
因为那里在Java中没有typdef你不能使用它们。最佳近似值可能是:
Since there are no typdefs in Java you cannot use them. The best approximation might be this:
public class Time32 extends UInt {
public Time32(){
super(5);
}
}
这篇关于在Java中实现typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!