Can I define custom types using primitives in Java?

For example, the following is the syntax correct code

Double number = 10.0;

Can I define my own class, such as price

Price myPrice = 10.0;

Actual compilation?

Solution

Automatic packing and unpacking are only applicable to primitives The concept you are talking about is similar to C conversion Unfortunately, there is no such thing in Java The best you can do is

Price myPrice = new Price(10.0);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>