public interface MyFunc<T> {
boolean func(T v1, T v2);
}
Run Code Online (Sandbox Code Playgroud)
public class HighTemp {
private int hTemp;
HighTemp(){
}
public HighTemp(int ht) {
this.hTemp = ht;
}
boolean sameTemp(HighTemp ht2){
return hTemp == ht2.hTemp;
}
boolean lessThanTemp(HighTemp ht2){
return hTemp < ht2.hTemp;
}
}
Run Code Online (Sandbox Code Playgroud)
class InstMethWithObjRef {
static <T> int counter(T[] vals, MyFunc<T> f, T v){
int count = 0;
for (int i = 0; i < vals.length; i++) {
if(f.func(vals[i], v)) count++;
}
return count;
}
public static void …Run Code Online (Sandbox Code Playgroud) interface New<T> {
boolean func(T n, T v);
}
Run Code Online (Sandbox Code Playgroud)
class MyFunc<T>{
T val;
MyFunc(T val){
this.val = val;
}
void Set(T val){
this.val = val;
}
T Get(){
return val;
}
boolean isEqual(MyFunc<T> o){
if(val == o.val) return true;
return false;
}
Run Code Online (Sandbox Code Playgroud)
public class Main {
static <T> boolean check(New<T> n , T a, T b){
return n.func(a,b);
}
public static void main(String args[]){
int a = 321;
MyFunc<Integer> f1 = new MyFunc<Integer>(a);
MyFunc<Integer> f2 = new MyFunc<Integer>(a);
boolean result; …Run Code Online (Sandbox Code Playgroud)