Created
October 10, 2014 16:25
-
-
Save olegchir/a0c482647569cf463ec8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Main { | |
public static void main(String[] args) { | |
БатяМолоток g = ()-> System.out.println("Привет"); | |
NickVolynkin.welcome(g); | |
} | |
} | |
class NickVolynkin { | |
public static <G extends IGuest<Item>> void welcome(G g) { | |
g.welcome(); /*, dear guest, please */ g.saySomething(); | |
//And now!!1 | |
g.getItems().forEach((item) -> System.out.println("КТО К НАМ С " + item + " ПРИДЕТ, ТОТ ОТ " + item + " И ПОГИБНЕТ")); | |
System.out.println("ибо нехуй по утрам будить."); | |
} | |
} | |
class Item {} | |
class Molotok extends Item { | |
@Override | |
public String toString() { | |
return "молоток"; | |
} | |
} | |
interface IGuest<T extends Item> { | |
default void saySomething() { | |
System.out.println("у меня есть:"); | |
List<T> items = getItems(); | |
for (T item : items) { | |
System.out.println(item); | |
} | |
if (null==items || items.isEmpty()) { | |
System.out.println("а ничего у меня нет"); | |
} | |
} | |
public abstract List<T> getItems(); | |
public abstract void welcome(); | |
} | |
@FunctionalInterface | |
interface БатяМолоток extends IGuest<Item> { | |
public List<Item> items = new ArrayList<Item>() {{ | |
add(new Molotok()); | |
}}; | |
@Override | |
default public List<Item> getItems() { | |
return items; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment