Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created October 10, 2014 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchir/a0c482647569cf463ec8 to your computer and use it in GitHub Desktop.
Save olegchir/a0c482647569cf463ec8 to your computer and use it in GitHub Desktop.
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