How to write nullable int in java?

前端 未结 3 1632
一向
一向 2020-12-29 19:14

I want to convert a web form to a model in Java.

In C# I can write this:




public class Test
{
           


        
3条回答
  •  被撕碎了的回忆
    2020-12-29 19:46

    You can use an Integer, which is a reference type (class)in Java and therefore nullable.

    Int32 (or int) is a struct (value type) in C#. In contrast, Integer in Java is a class which wraps an int. Instances of reference types can be null, which makes Integer an legit option.

    Nullable in .NET gives you similar options because it enables you to treat a value type like a nullable type. However, it's still different from Java's Integer since it's implemented as a struct (value type) which can be compared to null, but cannot actually hold a genuine null reference.

提交回复
热议问题