blob: e9dcd5439f3db6b2482890733f06110db90ab37a [file] [log] [blame]
package com.siyeh.igtest.migration.unnecessary_boxing;
public class UnnecessaryBoxing {
Integer foo(String foo, Integer bar) {
return foo == null ? Integer.valueOf(0) : bar;
}
public static void main(String[] args)
{
final Integer intValue = new Integer(3);
final Long longValue = new Long(3L);
final Long longValue2 = new Long(3);
final Short shortValue = new Short((short)3);
final Double doubleValue = new Double(3.0);
final Float floatValue = new Float(3.0F);
final Byte byteValue = new Byte((byte)3);
final Boolean booleanValue = new Boolean(true);
final Character character = new Character('c');
}
Integer foo2(String foo, int bar) {
return foo == null ? Integer.valueOf(0) : bar;
}
void noUnboxing(Object val) {
if (val == Integer.valueOf(0)) {
} else if (Integer.valueOf(1) == val) {}
boolean b = true;
Boolean.valueOf(b).toString();
}
public Integer getBar() {
return null;
}
void doItNow(UnnecessaryBoxing foo) {
Integer bla = foo == null ? Integer.valueOf(0) : foo.getBar();
}
private int i;
private String s;
public <T>T get(Class<T> type) {
if (type == Integer.class) {
return (T) new Integer(i);
} else if (type == String.class) {
return (T) s;
}
return null;
}
}
class IntIntegerTest {
public IntIntegerTest(Integer val) {
System.out.println("behavoiur 1");
}
public IntIntegerTest(int val) {
System.out.println("behavoiur 2");
}
public static void f(Integer val) {
System.out.println("behavoiur 1");
}
public static void f(int val) {
System.out.println("behavoiur 2");
}
public IntIntegerTest() {
}
public void test() {
new IntIntegerTest(new Integer(1)); // <-- incorrectly triggered
f(new Integer(1)); // <-- not triggered
}
}