allelopath
asked on
Boolean vs boolean as method parameter
For a method that has a Boolean parameter, as opposed to boolean, is it acceptable to use true or false?
For example, AbstractRenderer.setSeries VisibleInL egend(Bool ean visible):
For example, AbstractRenderer.setSeries
renderer.setSeriesVisibleInLegend(false);
or would it make a difference in doing:renderer.setSeriesVisibleInLegend(new Boolean(false));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You see how it works:
Output:
public class TestBoolean {
public static void takeBoolean(Boolean b){
System.out.println("Class of b:" + b.getClass());
System.out.println("Vlaue of b:" + b.booleanValue());
}
public static void main(String[] args) {
takeBoolean(true);
}
}
Output:
Class of b:class java.lang.Boolean
Vlaue of b:true
I think it will work only after Java 5 or 6 - when they introduced autoboxing which deals with those types like Integer, Boolean , Double...
read about autoboxing and un-boxing here:
http://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html
http://www.eclipse.org/aspectj/doc/released/adk15notebook/autoboxing.html
http://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html
http://www.eclipse.org/aspectj/doc/released/adk15notebook/autoboxing.html
The only difference would be if there is overloading
See an example
See an example
here we defined two methdos which differe that one tkaes boolean and anothe takse Boolean,
then in thios case it will take the method wchich uses Boolean:
Output:
then in thios case it will take the method wchich uses Boolean:
public class testBooolean {
public static void takeBoolean(boolean b){
System.out.println("I type here something else");
}
public static void takeBoolean(Boolean b){
System.out.println("Class of b:" + b.getClass());
System.out.println("Vlaue of b:" + b.booleanValue());
}
public static void main(String[] args) {
takeBoolean(new Boolean(true));
}
}
Output:
Class of b:class java.lang.Boolean
Vlaue of b:true
however in this case:
it wil use method which has argiment of boolean:
(unless you have tw exactly identical methods which only differe by Bollean vs boolens - then you do not care. This is just exotic example
Output
it wil use method which has argiment of boolean:
(unless you have tw exactly identical methods which only differe by Bollean vs boolens - then you do not care. This is just exotic example
public class TestBoolean{
public static void takeBoolean(boolean b){
System.out.println("I type here something else");
}
public static void takeBoolean(Boolean b){
System.out.println("Class of b:" + b.getClass());
System.out.println("Vlaue of b:" + b.booleanValue());
}
public static void main(String[] args) {
takeBoolean(true);
}
}
Output
I type here something else
public static void takeBoolean(Boolean b){
}
public static void main(String[] args) {
takeBoolean(true);
}