开发者

declare a method that can except nullable Int or String in java (Android)

As per This Post..it is said that Java does not have a nullable feature as C# has. but i have seen many methods in Android Sdk that accepts 'null' as parameters for e.g see this method

SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("address@example.com", null, "Message body here", null, null);

In the above sentTextMessage method, it is accepting null as开发者_JAVA百科 parameters, i have a my method that accepts String as parameters i also want to pass null in some condition how can i do that ? in C# i can do public void methodName(int? param1) but in java how to do that..here is my method that should accept null also

public boolean update(long rowId,String status_receive,String status_send){/*xyz*/}

update(2,null,"yes") // error Invalid Argument,

My Question is how to declare a method that can accepts null values also ?


Typically you would use the wrapper classes in the java.lang package - e.g. Integer for int, Long for long etc. Auto-boxing will convert primitive values into objects where necessary - but be aware that this is different from .NET nullable types in that it does use full objects, rather than value types with an extra flag.


Anything which is not a primitive type (int, byte, char etc.) can be null in Java. There is no need or possibility to declare anything on that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜