Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface MyFunc<T> { boolean func(T v1, T v2); }
- class HighTemp {
- private int hTemp;
- HighTemp(int ht) { hTemp = ht; }
- boolean lessThanTemp(HighTemp ht2) {
- return hTemp < ht2.hTemp;
- }
- }
- class InstanceMethWithObjectRefDemo {
- static <T> int counter(T[] vals, MyFunc<T> f, T v) {
- int count = 0;
- for(int i=0; i < vals.length; i++)
- //*** THIS LINE
- if(f.func(vals[i],v)) count++;
- return count;
- }
- public static void main(String args[])
- {
- int count;
- HighTemp[] weekDayHighs2 = { new HighTemp(32), new HighTemp(12),
- new HighTemp(24), new HighTemp(19),
- new HighTemp(18), new HighTemp(12),
- new HighTemp(-1), new HighTemp(13) };
- count = counter(weekDayHighs2, HighTemp::lessThanTemp,
- new HighTemp(19));
- System.out.println(count + " days had a high of less than 19");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement