public class Expons{
static Stores st;
public static void main(String argv[]){
st=new Stores();
Object ob1=getFormattedObject(Pattern.compile("H[a-d][k-m]"), "H[a-b][k-m]");
Object ob2=getFormattedObject(st.pt1.matcher("Hello Hallo"), "[a-e][l]lo");
Object ob3=getFormattedObject(null); // #1
System.out.println(ob3);
}
public static Object getFormattedObject(Object ob, String... s){
if (ob instanceof Pattern){
st.pt1=((Pattern)ob).compile(s[0]);
return null;
}else if (ob instanceof Matcher){
st.mt1=(Matcher)ob;
return null;
}else{
st.mt1.find();
st.st1=st.mt1.group();
return st.st1;
}
}
}
class Stores{
Pattern pt1; Matcher mt1; String st1;
}
Eu respondi que o programa não compilaria porque na linha #1 ele ta passando somente 1 parametro pra um método que supostamente recebe 2… Esse programa compila e imprime “Hal”.
Como funciona isso?