728x90


java 8

try with resource  : doc 보기

1
2
3
        try (Connection connection = DriverManager.getConnection(url, username, password)){
            System.out.println("Connection create:"+connection);
        }


lambda : doc 보기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    public static void main(String[] args) {
 
        List<Person> people = Arrays.asList(//
                new Person("Charles""Dickens"60), new Person("Lewis""Carroll"42),
                new Person("Thomas""Carlyle"51), new Person("Charlotte""Brante"45),
                new Person("Mattew""Arnold"39));
  //--> 이부분
        System.out.println("Printing all persons");
        //System.out.println(person)  :
        // p -> method(p)
        //person -> System.out.println(person)
        printConditionaly(people, person -> trueSystem.out::println);
    }
 
    private static void printConditionaly(List<Person> people, Predicate<Person> predicate, Consumer<Person> consumer) {
        for (Person person : people) {
            if (predicate.test(person))
                consumer.accept(person);
        }
    }
cs


+ Recent posts