24 lines
807 B
Java
24 lines
807 B
Java
|
package TypeCheck;
|
||
|
|
||
|
import java.util.Objects;
|
||
|
|
||
|
public class TypeCheckHelper {
|
||
|
public String upperBound(String type1, String type2) throws Exception{
|
||
|
boolean type1Primitiv = Objects.equals(type1, "bool") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
||
|
boolean type2Primitiv = Objects.equals(type2, "bool") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
||
|
|
||
|
String result;
|
||
|
if(type1Primitiv && type2Primitiv){
|
||
|
if(Objects.equals(type1, type2)){
|
||
|
result = type1;
|
||
|
}
|
||
|
throw new Exception("no upper bound");
|
||
|
}else if(type1Primitiv || type2Primitiv){
|
||
|
throw new Exception("no upper bound");
|
||
|
}else{
|
||
|
result = "class";
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
}
|