简体   繁体   English

如何为我的Java项目实现基本数据类型

[英]How to implement basic data type for my Java project

I normally work for C++. 我通常为C ++工作。 Now coding for Java, I know that Java doesn't have typedef and I have to implement my own object for my basic data type object as 现在编写Java代码,我知道Java没有typedef ,我必须为我的基本数据类型对象实现自己的对象

public class FundamentalDataType<T> {
      public T x;
}

So T represents my basic data type and if T is Double, the whole project is using double, if Float the whole project is using Float. 所以T表示我的基本数据类型,如果T是Double,整个项目使用double,如果Float整个项目使用Float。 But when I make another Class extending FundamentalDataType , I have error if I write as 但是当我创建另一个扩展FundamentalDataType Class ,如果我写为,则会出错

public class Euclidean_Distance_Function extends FundamentalDataType<T>

if it is line 如果它是线

public class Euclidean_Distance_Function extends FundamentalDataType<Double>

That deviates my idea of making FundamentalDataType class. 这偏离了我制作FundamentalDataType类的想法。 How can I implement that concept in Java? 如何在Java中实现该概念?

If the subclass is going to use the same data type of the superclass, declare it as: 如果子类将使用超类的相同数据类型,则将其声明为:

public class Euclidean_Distance_Function<T> extends FundamentalDataType<T> 
{ ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM