Maya1991

Lambda Expression

Jan 6th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. ▪️Test85.java
  2. import java.util.function.*;
  3.  
  4. public class Test85 {
  5.     public static void main(String[] args) {
  6.         // Hero85 h = new Hero85();
  7.         // Cat85 = (Cat85 c) -> {
  8.         // return c.getHp();
  9.         // };
  10.  
  11.         Supplier<Cat85> supplier = () -> new Cat85();
  12.         int hp = supplier.get().getHp();
  13.  
  14.         System.out.println(hp);
  15.     }
  16. }
  17.  
  18. ▪️Cat85.java
  19. public interface Cat85 {
  20.     public int hp = 20;
  21.  
  22.     // Cat85() {
  23.     // this.hp = 100;
  24.     // }
  25.  
  26.     public  abstract int getHp() {
  27.         return this.hp;
  28.     }
  29.  
  30. }
  31.  
  32.  
  33. ▪️Error Log
  34. The local variable c may not have been
  35.  initialized
  36. Abstract methods do not specify a
  37.  body
Advertisement
Add Comment
Please, Sign In to add comment