[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/java-orange/learnData/main/java8/java8.md [Back]  [Original]

[toc] # 1. Java 8 ## 1.1 - Lambda - - / - Stream API - / - API - ## 1.2 - - - Stream API - - Optional (Kotlin ?) ## 1.3 - Hashmap / - hashmap - Java - Java # 2. Lambda ## 2.1 LambdaJava ## 2.2 ```java @Test public void test01(){ // Comparator comparator = new Comparator() { @Override public int compare(Integer o1, Integer o2) { return Integer.compare(o1,o2); } @Override public boolean equals(Object obj) { return false; } }; // TreeSet set = new TreeSet(comparator); } ``` ## 2.3 Lambda ```java @Test public void test02(){ // Lambda Comparator comparator = (a, b) -> Integer.compare(a, b); TreeSet set = new TreeSet(comparator); } ``` ``` - --> --> --> Lambda --> Stream Api 35 : 35 5000 5000 ------------------------------------------------- MyPredicate boolean boolean filter() public interface MyPredicate{ boolean filter(T t); } public class AgeFilter implements MyPredicate(){ @Override public boolean filter(Employee emp){ return emp.getAge() >= 35; } } public List getSpecial(List list, MyPredicate mp) { List emps = new ArraysList(); list.forEach(Emp -> { if (mp.filter(emp)) { emps.add(emp); } }) return emps; } ------------------------------------------ public void test() { List list = Arrays.asList( new Employee('001',35,4000); new Employee('002',65,3000); new Employee('003',25,8000); new Employee('004',85,7000); ); List emps = this.getSpecial(list,new MyPredicate() { @Override public boolean filter(Employee emp) { return emp.getSalary emp.getSalary e.getSalray >= 4000) .forEach(System.out::println); // list.stream() .filter(e -> e.gatSalary >= 4000) .limit(2).forEach(System.out::println); // list.stream() .map(Employee::getName) .forEach(System.out::println); } ``` Lambda Lambda `->` `` `` ```java -> / Lambda ``` - - - - () -> sout Runnable ```java public class Test02 { int num = 10; //jdk 1.7 final @Test public void test01(){ // new Runnable() { @Override public void run() { // // System.out.println("Hello World" + num); } }; } @Test public void test02(){ // Runnable runnable = () -> { System.out.println("Hello Lambda"); }; } } ``` - ```java @Test public void test03(){ Consumer consumer = (a) -> System.out.println(a); consumer.accept(""); } ``` - ```java @Test public void test03(){ Consumer consumer = a -> System.out.println(a); consumer.accept(""); } ``` - Lambda ```java @Test public void test04(){ Comparator comparator = (a, b) -> { System.out.println(""); return Integer.compare(a, b); }; } ``` - Lambda 1 return ```java @Test public void test04(){ Comparator comparator = (a, b) -> Integer.compare(a, b); } ``` - Lambda Jvm **** - @FunctionalIterface - ```java @FunctionalInterface public interface MyFun { Integer count(Integer a, Integer b); } ``` - ```java @Test public void test05(){ MyFun myFun1 = (a, b) -> a + b; MyFun myFun2 = (a, b) -> a - b; MyFun myFun3 = (a, b) -> a * b; MyFun myFun4 = (a, b) -> a / b; } ``` - ```java public Integer operation(Integer a, Integer b, MyFun myFun){ return myFun.count(a, b); } @Test public void test06(){ Integer result = operation(1, 2, (x, y) -> x + y); System.out.println(result); } ``` ## 2.4 **** Collections.sort() `` Employee () Lambda - ```java @Data @NoArgsConstructor @AllArgsConstructor public class Employee { private Integer id; private String name; private Integer age; private Double salary; } ``` - List ```java List emps = Arrays.asList( new Employee(101, "Z3", 19, 9999.99), new Employee(102, "L4", 20, 7777.77), new Employee(103, "W5", 35, 6666.66), new Employee(104, "Tom", 44, 1111.11), new Employee(105, "Jerry", 60, 4444.44) ); ``` - @Test ```java @Test public void test01(){ Collections.sort(emps, (e1, e2) -> { if (e1.getAge() == e2.getAge()){ return e1.getName().compareTo(e2.getName()); } else { return Integer.compare(e1.getAge(), e2.getAge()); // return -Integer.compare(e1.getAge(),e2.getAge()); } }); for (Employee emp : emps) { System.out.println(emp); } } ``` ****String getValue(String str); TestLambda ```java // 1. () @FunctionalInterface public Interface MyFunc() { String getValue(String str); } // 2. public class TestLambda{ public String strHandler(String str, MyFunc mp) { return mp.getValue(str); } @Test public void test(){ System.out.println(strHandler("abcd",(str) -> str.toUpperCase())); System.out.println(strHandler("",() -> str.substring(2))); } } ``` **** T R TestLambda Long Long ```java // @FunctionalInterface public interface MyFun{ R getValue(T t1, T t2); } // public class TestLamdba{ public void numHandler(Long t1, Long t2, MyFun f) { System.out.println(f.getValue(t1,t2)); } @test public void test() { numHandler(100L,200L,(x,y) -> x + y); numHandler(100L,299L,(x,y) -> x * y); } } ``` Java84 1. ```java Consumer void accept(T t); ``` 2. ```java Supplier T get(); ``` 3. ```java Function R apply(T t) ``` 4. ```java Predicate boolean test(T t) ``` # 3. () Java
Consumer
TvoidTvoid accept(T t)
Supplier
TTT get()
Function<T, R>
TRTRR apply(T t)
Predicate
TbooleanTbooleanboolean test(T t)
## 3.1 ```java @Test public void test01(){ public static void main(String[] args) { happy(1000,(x) -> System.out.println("" + x + "")); } public void happy(double money,Consumer con) { con.accept(money); } } ``` ## 3.2 ```java @Test public void test02(){ public static void main(String[] args) { List list = getNumList(5,() -> (Integer)Math.random() *100); } // . public List getNumList(Integer num, Supplier sp) { List list = new ArrayList(); for(int i = 0; i < num; i ++) { list.add(sp.get()); } } } ``` ## 3.3 ```java @Test public void test03(){ public static void main(String[] args) { strHandler("abcd",(x) -> x.toUpperCase()); strHandler("abcdef", (x) -> x.substring(2,5)); } public void strHandler(String str, Function func) { System.out.println(func.apply(str)); } } ``` ## 3.4 ```java @Test public void test04(){ public static void main(String[] args) { List list = Arrays.asList("12341324","1341324","1353534"); List ll = see(list,(x) -> x.length() > 5); } public List see(List strs, Predicate pre) { List list = new ArrayList(); for (String str : strs) { if (pre.test(str)){ list.add(str); } } return list; } } ``` ## 3.5 ![](java8.assets/20200518225311406.png) # 4. ## 4.1 **** Lambda `` - :: - :: - :: **::** ```java @Test public void test01(){ PrintStream ps = System.out; Consumer con1 = (s) -> ps.println(s); con1.accept("aaa"); Consumer con2 = System.out::println; con2.accept("bbb"); } ``` ********Lambda **** **::** ```java @Test public void test02(){ Comparator com1 = (x, y) -> Integer.compare(x, y); System.out.println(com1.compare(1, 2)); Comparator com2 = Integer::compare; System.out.println(com2.compare(2, 1)); } ``` **::** ```java @Test public void test03(){ BiPredicate bp1 = (x, y) -> x.equals(y); System.out.println(bp1.test("a","b")); BiPredicate bp2 = String::equals; System.out.println(bp2.test("c","c")); } ``` ****Lambda ClassName :: Method ## 4.2 - ClassName :: new ```java @Test public void test04(){ Supplier sup1 = () -> new ArrayList(); Supplier sup2 = ArrayList::new; } ``` **** ## 4.3 - Type :: new; # 5. Stream API ## 5.1 Stream? ![](java8.assets/20200518225358689.png) Stream ![](java8.assets/20200518225430446.png) ```java /** * */ @Test public void test01(){ /** * * - Collection.stream() * - Collection.parallelStream() */ List list = new ArrayList(); Stream stream1 = list.stream(); // //Arrays.stream(array) String[] strings = new String[10]; Stream stream2 = Arrays.stream(strings); //Stream //Stream.of(...) Stream stream3 = Stream.of(1, 2, 3); // // Stream stream4 = Stream.iterate(0, (i) -> i+2); stream4.forEach(System.out::println); // // Stream.generate(() -> Math.random()) .limit(5) .forEach(System.out::println); } ``` ## 5.2 / - `filter` Lambda - `limit` - `skip(n)`nn limit(n) - `distinct` hashCode() equals() ```java List emps = Arrays.asList( new Employee(101, "Z3", 19, 9999.99), new Employee(102, "L4", 20, 7777.77), new Employee(103, "W5", 35, 6666.66), new Employee(104, "Tom", 44, 1111.11), new Employee(105, "Jerry", 60, 4444.44) ); @Test public void test01(){ emps.stream() .filter((x) -> x.getAge() > 35) .limit(3) .distinct() .skip(1) .forEach(System.out::println); } ``` Stream ![](java8.assets/20200518225456187.png) - Stream API - ## 5.3 - `map` Lambda - `flatMap` map ```java @Test public void test02(){ List list = Arrays.asList("a", "b", "c"); list.stream() .map((str) -> str.toUpperCase()) .forEach(System.out::println); } ``` flatMap ```java public Stream filterCharacter(String str){ List list = new ArrayList(); for (char c : str.toCharArray()) { list.add(c); } return list.stream(); } @Test public void test03(){ List list = Arrays.asList("a", "b", "c"); Test02 test02 = new Test02(); list.stream() .flatMap(test02::filterCharacter) .forEach(System.out::println); } ``` ## 5.4 - sorted() (Comparable) - sorted(Comparator c) Comparable ```java @Test public void test04(){ List list = Arrays.asList(1,2,3,4,5); list.stream() .sorted() //Comparable.comparaTo() .forEach(System.out::println); } ``` Comparator ```java @Test public void test05(){ emps.stream() .sorted((e1, e2) -> { //comparator() if (e1.getAge().equals(e2.getAge())){ return e1.getName().compareTo(e2.getName()); // - // return -e1.getName().compareTo(e2.getName()); } else { return e1.getAge().compareTo(e2.getAge()); } }) .forEach(System.out::println); } ``` ## 5.5 / - allMatch - anyMatch - noneMatch - findFirst - findAny - count - max - min ```java public enum Status { FREE, BUSY, VOCATION; } @Test public void test01(){ List list = Arrays.asList(Status.FREE, Status.BUSY, Status.VOCATION); boolean flag1 = list.stream() .allMatch((s) -> s.equals(Status.BUSY)); System.out.println(flag1); boolean flag2 = list.stream() .anyMatch((s) -> s.equals(Status.BUSY)); System.out.println(flag2); boolean flag3 = list.stream() .noneMatch((s) -> s.equals(Status.BUSY)); System.out.println(flag3); // Optional op1 = list.stream() .findFirst(); // Optional Status s1 = op1.orElse(Status.BUSY); System.out.println(s1); Optional op2 = list.stream() .findAny(); System.out.println(op2); long count = list.stream() .count(); System.out.println(count); Optional op1 = list.stream().max((e1, e2) -> Double.compare(e1.getSalary(),e2.getSalary())); System.out.println(op1.get()); Double salary = list.stream().map(Employee::getSalary()).max(Double::compare); System.out.println(salary); } ``` ## 5.6 / - reduce(T identity, BinaryOperator) / reduce(BinaryOperator) - collect Collector reduce ```java /** * Java * - reduce * Kotlin * - fold * - reduce */ @Test public void test01(){ List list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9); Integer integer = list.stream() .reduce(0, (x, y) -> x + y); System.out.println(integer); Optional op = list.stream().map(Employee::getSalary()).reduce(Double::sum); System.out.println(op.get()); } ``` collect ![](java8.assets/20200518225526879.png) ```java List emps = Arrays.asList( new Employee(101, "Z3", 19, 9999.99), new Employee(102, "L4", 20, 7777.77), new Employee(103, "W5", 35, 6666.66), new Employee(104, "Tom", 44, 1111.11), new Employee(105, "Jerry", 60, 4444.44) ); @Test public void test02(){ //List List list = emps.stream() .map(Employee::getName) .collect(Collectors.toList()); list.forEach(System.out::println); //Set Set set = emps.stream() .map(Employee::getName) .collect(Collectors.toSet()); set.forEach(System.out::println); //LinkedHashSet, LinkedHashSet linkedHashSet = emps.stream() .map(Employee::getName) .collect(Collectors.toCollection(LinkedHashSet::new)); linkedHashSet.forEach(System.out::println); } @Test public void test03(){ // Long count = emps.stream() .collect(Collectors.counting()); System.out.println(count); // Double avg = emps.stream() .collect(Collectors.averagingDouble(Employee::getSalary)); System.out.println(avg); // Double sum = emps.stream() .collect(Collectors.summingDouble(Employee::getSalary)); System.out.println(sum); // Optional max = emps.stream() .collect(Collectors.maxBy((e1, e2) -> Double.compare(e1.getSalary(), e2.getSalary()))); System.out.println(max.get()); // Optional min = emps.stream() .map(Employee::getSalary) .collect(Collectors.minBy(Double::compare)); System.out.println(min.get()); } @Test public void test04(){ // Map map = emps.stream() .collect(Collectors.groupingBy(Employee::getStatus)); System.out.println(map); // Map mapMap = emps.stream() .collect(Collectors.groupingBy(Employee::getStatus, Collectors.groupingBy((e) -> { if (e.getAge() > 35) { return ""; } else if (e.getAge() > 55){ return ""; }else { return ""; } }))); System.out.println(mapMap); // Map listMap = emps.stream() .collect(Collectors.partitioningBy((e) -> e.getSalary() > 4321)); System.out.println(listMap); } @Test public void test05(){ // DoubleSummaryStatistics dss = emps.stream() .collect(Collectors.summarizingDouble(Employee::getSalary)); System.out.println(dss.getMax()); System.out.println(dss.getMin()); System.out.println(dss.getSum()); System.out.println(dss.getCount()); System.out.println(dss.getAverage()); // String str = emps.stream() .map(Employee::getName) .collect(Collectors.joining("-","","")); // System.out.println(str); } ``` ## 5.7 ****(123451491625) ```java @Test public void test01(){ List list = Arrays.asList(1, 2, 3, 4, 5); list.stream() .map((x) -> x * x) .forEach(System.out::println); } ``` **** map reduce Employee ```java List emps = Arrays.asList( new Employee(101, "Z3", 19, 9999.99), new Employee(102, "L4", 20, 7777.77), new Employee(103, "W5", 35, 6666.66), new Employee(104, "Tom", 44, 1111.11), new Employee(105, "Jerry", 60, 4444.44) ); @Test public void test02(){ Optional result = emps.stream() .map((e) -> 1) .reduce(Integer::sum); System.out.println(result.get()); ``` **** ```java package com.atguigu.exer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Stream; import org.junit.Before; import org.junit.Test; public class TestTransaction { List transactions = null; @Before public void before(){ Trader raoul = new Trader("Raoul", "Cambridge"); Trader mario = new Trader("Mario", "Milan"); Trader alan = new Trader("Alan", "Cambridge"); Trader brian = new Trader("Brian", "Cambridge"); transactions = Arrays.asList( new Transaction(brian, 2011, 300), new Transaction(raoul, 2012, 1000), new Transaction(raoul, 2011, 400), new Transaction(mario, 2012, 710), new Transaction(mario, 2012, 700), new Transaction(alan, 2012, 950) ); } //1. 2011 @Test public void test1(){ transactions.stream() .filter((t) -> t.getYear() == 2011) .sorted((t1, t2) -> Integer.compare(t1.getValue(), t2.getValue())) .forEach(System.out::println); } //2. @Test public void test2(){ transactions.stream() .map((t) -> t.getTrader().getCity()) .distinct() .forEach(System.out::println); } //3. @Test public void test3(){ transactions.stream() .filter((t) -> t.getTrader().getCity().equals("Cambridge")) .map(Transaction::getTrader) .sorted((t1, t2) -> t1.getName().compareTo(t2.getName())) .distinct() .forEach(System.out::println); } //4. @Test public void test4(){ transactions.stream() .map((t) -> t.getTrader().getName()) .sorted() .forEach(System.out::println); System.out.println("-----------------------------------"); String str = transactions.stream() .map((t) -> t.getTrader().getName()) .sorted() .reduce("", String::concat); System.out.println(str); System.out.println("------------------------------------"); transactions.stream() .map((t) -> t.getTrader().getName()) .flatMap(TestTransaction::filterCharacter) .sorted((s1, s2) -> s1.compareToIgnoreCase(s2)) .forEach(System.out::print); } public static Stream filterCharacter(String str){ List list = new ArrayList(); for (Character ch : str.toCharArray()) { list.add(ch.toString()); } return list.stream(); } //5. @Test public void test5(){ boolean bl = transactions.stream() .anyMatch((t) -> t.getTrader().getCity().equals("Milan")); System.out.println(bl); } //6. @Test public void test6(){ Optional sum = transactions.stream() .filter((e) -> e.getTrader().getCity().equals("Cambridge")) .map(Transaction::getValue) .reduce(Integer::sum); System.out.println(sum.get()); } //7. @Test public void test7(){ Optional max = transactions.stream() .map((t) -> t.getValue()) .max(Integer::compare); System.out.println(max.get()); } //8. @Test public void test8(){ Optional op = transactions.stream() .min((t1, t2) -> Integer.compare(t1.getValue(), t2.getValue())); System.out.println(op.get()); } } ``` ## 5.8 - - Java 8 Stream API parallel() sequential() Fork / Join ![](java8.assets/2020051822555569.png) Fork / Join ![](java8.assets/20200518225613845.png) Fork / Join ```java public class ForkJoinCalculate extends RecursiveTask { private static final long serialVersionUID = 1234567890L; private long start; private long end; private static final long THRESHPLD = 10000; public ForkJoinCalculate(long start, long end) { this.start = start; this.end = end; } @Override protected Long compute() { long length = end - start; if (length new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); public static Date convert(String source) throws ParseException{ return df.get().parse(source); } } @Test public void test02(){ Callable task = () -> DateFormatThreadLocal.convert("20200517"); ExecutorService pool = Executors.newFixedThreadPool(10); ArrayList result = new ArrayList(); for (int i = 0; i < 10; i++) { result.add(pool.submit(task)); } for (Future future : result) { try { System.out.println(future.get()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } pool.shutdown(); } ``` DateTimeFormatter ```java @Test public void test03(){ DateTimeFormatter dtf = DateTimeFormatter.ISO_LOCAL_DATE; Callable task = () -> LocalDate.parse("20200517",dtf); ExecutorService pool = Executors.newFixedThreadPool(10); ArrayList result = new ArrayList(); for (int i = 0; i < 10; i++) { result.add(pool.submit(task)); } for (Future future : result) { try { System.out.println(future.get()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } pool.shutdown(); } ``` ## 8.2 / ISO ![](java8.assets/20200518225724271.png) | | | | | ------------------------------------------------------------ | -------------------- | ------------------------------------------------------------ | | now( ) | static LocalDateTime | | | of(int year, int month, int dayOfMonth, int hour, int minute, int second) | static LocalDateTime | LocalDateTime | | plus(long amountToAdd, TemporalUnit unit) | LocalDateTime | | | get(TemporalField field) | int | int | @Test ```java @Test public void test01(){ // now LocalDateTime ldt1 = LocalDateTime.now(); System.out.println(ldt1); // of LocalDateTime ldt2 = LocalDateTime.of(2020, 05, 17, 16, 24, 33); System.out.println(ldt2); // plus LocalDateTime ldt3 = ldt2.plusYears(2); System.out.println(ldt3); // minus LocalDateTime ldt4 = ldt2.minusMonths(3); System.out.println(ldt4); //... get System.out.println(ldt2.getDayOfYear()); System.out.println(ldt2.getHour()); System.out.println(ldt2.getSecond()); } ``` LocalDate / LocalTime ## 8.3 Instant Unix 1970-01-01 00:00:00 @Test ```java @Test public void test02(){ // UTC (UTC) Instant ins1 = Instant.now(); System.out.println(ins1); // (UTC + 8) OffsetDateTime odt1 = ins1.atOffset(ZoneOffset.ofHours(8)); System.out.println(odt1); // long milli1 = ins1.toEpochMilli(); System.out.println(milli1); // Instant ins2 = Instant.ofEpochSecond(60); System.out.println(ins2); } ``` ## 8.4 / - Duration - Period @Test ```java @Test public void test03(){ // between Instant ins1 = Instant.now(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } Instant ins2 = Instant.now(); Duration dura1 = Duration.between(ins1, ins2); System.out.println(dura1.getSeconds()); System.out.println(dura1.toMillis()); } @Test public void test04(){ LocalDate ld1 = LocalDate.of(2016, 9, 1); LocalDate ld2 = LocalDate.now(); Period period = Period.between(ld1, ld2); // ISO System.out.println(period.getYears()); System.out.println(period.toTotalMonths()); } ``` ## 8.5 ![](java8.assets/20200518225752314.png) @Test ```java @Test public void test01(){ //TemporalAdjusters LocalDateTime ldt1 = LocalDateTime.now(); System.out.println(ldt1); // ... LocalDateTime ldt2 = ldt1.withDayOfMonth(10); System.out.println(ldt2); // LocalDateTime ldt3 = ldt1.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)); System.out.println(ldt3); // LocalDateTime ldt5 = ldt1.with((ta) -> { LocalDateTime ldt4 = (LocalDateTime) ta; DayOfWeek dow1 = ldt4.getDayOfWeek(); if (dow1.equals(DayOfWeek.FRIDAY)) { return ldt4.plusDays(3); } else if (dow1.equals(DayOfWeek.SATURDAY)) { return ldt4.plusDays(2); } else { return ldt4.plusDays(1); } }); System.out.println(ldt5); } ``` ## 8.6 - DateTimeFormatter / ```java @Test public void test01(){ // DateTimeFormatter dtf1 = DateTimeFormatter.ISO_DATE_TIME; LocalDateTime ldt1 = LocalDateTime.now(); String str1 = ldt1.format(dtf1); System.out.println(str1); // ofPattern DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime ldt2 = LocalDateTime.now(); String str2 = ldt2.format(dtf2); System.out.println(str2); // LocalDateTime newDate = ldt1.parse(str1, dtf1); System.out.println(newDate); } ``` ## 8.7 - ZonedDate - ZonedTime - ZonedDateTime @Test ```java @Test public void test02(){ // Set set = ZoneId.getAvailableZoneIds(); set.forEach(System.out::println); // LocalDateTime ldt1 = LocalDateTime.now(ZoneId.of("Europe/Tallinn")); System.out.println(ldt1); // LocalDateTime ldt2 = LocalDateTime.now(ZoneId.of("Europe/Tallinn")); ZonedDateTime zdt1 = ldt2.atZone(ZoneId.of("Europe/Tallinn")); System.out.println(zdt1); } ``` ```java @Test public void test03(){ // Date LocalDateTime Date date = new Date(); Instant instant = date.toInstant(); ZoneId zoneId = ZoneId.systemDefault(); LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime(); // LocalDateTime Date LocalDateTime localDateTime = LocalDateTime.now(); ZoneId zoneId = ZoneId.systemDefault(); ZonedDateTime zdt = localDateTime.atZone(zoneId); Date date = Date.from(zdt.toInstant()); // Instant } ``` # 9. ## 9.1 ```java @Repeatable(MyAnnotations.class) // @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { String value() default "Java 8"; } ``` ```java @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotations { MyAnnotation[] value(); } ``` @Test ```java public class Test01 { // @Test @MyAnnotation("Hello") @MyAnnotation("World") public void test01() throws NoSuchMethodException { Class clazz = Test01.class; Method test01 = clazz.getMethod("test01"); MyAnnotation[] mas = test01.getAnnotationsByType(MyAnnotation.class); for (MyAnnotation ma : mas) { System.out.println(ma.value()); } } } ``` ## 9.2 Java 8 ElementType.TYPE_USE ElementType.TYPE_PARAMETERTarget
Web Proxy Viewer  |  New URL  |  Original Page