I want to write a public method that passes in two objects of the same type an and b, and returns b
if an is nullpublic static ifObj(Object a, Object b) {
if(null == a) {
return b;
}else {
return a;
}
}
Obj obj = ifObj(xxx, new xxx());
but the result of doing so will have to be transformed. I want to modify it on the basis of ifObj. Call the method to pass an object type or generic type, and judge that an is null, and return an object based on the type or generic generic type. Is this all right? how should the syntax be written to achieve it?