java-8

How does Spring use Java 8 classes, yet it runs on Java 7?

烈酒焚心 提交于 2020-01-23 13:58:08
问题 I recently downloaded the source code for the Spring MVC (Version 4.0.2.RELEASE) module within the Spring Framework. My intention is to run against the actual source code for the module instead of the actual .jar file. (Long story, only for testing purposes). After downloading the source code, I removed the jar file from my project, compiled and deployed to the server. When I hit one of the URLs handled by the dispatcher servlet I was presented with the error: org.springframework.beans

ASM - java.lang.VerifyError: Operand stack overflow Exception

强颜欢笑 提交于 2020-01-23 11:13:31
问题 I am using ASM 5.0.3 byte code library with Tomcat 8 and JDK 8. Also I am using ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES); and classReader.accept(myClassVisitor, ClassReader.SKIP_FRAMES); Below exception is thrown by ASM Caused by: java.lang.VerifyError: Operand stack overflow Exception Details: Location: org/apache/tomcat/websocket/server/WsServerContainer.addEndpoint(Ljavax/websocket/server/ServerEndpointConfig;)V @0: aload_0 Reason: Exceeded max

ASM - java.lang.VerifyError: Operand stack overflow Exception

久未见 提交于 2020-01-23 11:12:13
问题 I am using ASM 5.0.3 byte code library with Tomcat 8 and JDK 8. Also I am using ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES); and classReader.accept(myClassVisitor, ClassReader.SKIP_FRAMES); Below exception is thrown by ASM Caused by: java.lang.VerifyError: Operand stack overflow Exception Details: Location: org/apache/tomcat/websocket/server/WsServerContainer.addEndpoint(Ljavax/websocket/server/ServerEndpointConfig;)V @0: aload_0 Reason: Exceeded max

Java Stream API storing lambda expression as variable

只愿长相守 提交于 2020-01-23 09:46:29
问题 This title sounds stupid even to me, but there must be at least somewhat clever way to achieve such effect and I don't know how else to explain it. I need to sort array using sorted in stream API. Here is my stream so far: Arrays.stream(sequence.split(" ")) .mapToInt(Integer::parseInt) .boxed() .sorted((a, b) -> a.compareTo(b)) .forEach(a -> System.out.print(a + " ")); Now I have two different sorts of course - ascending and descending and the sort I need to use is specified in the user input

Map<String,List<String>> to Pair<String,String>

我的未来我决定 提交于 2020-01-23 08:27:34
问题 Using Java 8 Stream API how can I flat a Map to Pair list where left pair value is the map key? Example: If given map was 1 => {1, 2, 3} 2 => {2, 4} Then desired output is the stream of five pairs: (1,1) , (1,2) , (1,3) , (2,2) , (2,4) 回答1: List<Pair<String, String>> result = map.entrySet() .stream() .flatMap( entry -> entry.getValue() .stream() .map(string -> new Pair<>(entry.getKey(), string))) .collect(Collectors.toList()); 来源: https://stackoverflow.com/questions/32189147/mapstring

Java 8 Optional asSet()

99封情书 提交于 2020-01-23 07:52:33
问题 So I have been using Guava's Optional for a while now, and I moving to Java 8 so I wanted to use it's Optional class, but it doesn't have my favorite method from Guava, asSet(). Is there a way to do this with the Java 8 Optional that I am not seeing. I love being able to treat optional as a collection so I can do this: for( final User u : getUserOptional().asSet() ) { return u.isPermitted(getPermissionRequired()); } In some cases avoids the need for an additional variable. IE Optional<User>

java stream Collectors.groupingBy() multiple fields

佐手、 提交于 2020-01-23 06:50:06
问题 Stream<Map.Entry<String, Long>> duplicates = notificationServiceOrderItemDto.getService() .getServiceCharacteristics() .stream() .collect( Collectors.groupingBy( ServiceCharacteristicDto::getName, Collectors.counting() ) ) .entrySet() .stream() .filter(e -> e.getValue() > 1); Optional<String> dupName = duplicates.map(Map.Entry::getKey).findFirst(); works perfect. But I wold like to find duplicates not just with name but also name + value + key That means if name + value + key is the same this

Printing certain values using Collections.frequency()

北城以北 提交于 2020-01-23 06:34:39
问题 I have an array as follows: int[] array = {11, 14, 17, 11, 48, 33, 29, 11, 17, 22, 11, 48, 18}; What I wanted to do was to find the duplicate values, and print them. So my way of doing this was to convert to ArrayList , then to Set and use a stream on the Set . ArrayList<Integer> list = new ArrayList<>(array.length); for (int i = 0; i < array.length; i++) { list.add(array[i]); } Set<Integer> dup = new HashSet<>(list); I then used a stream to loop through it and print the values using

Printing certain values using Collections.frequency()

[亡魂溺海] 提交于 2020-01-23 06:34:09
问题 I have an array as follows: int[] array = {11, 14, 17, 11, 48, 33, 29, 11, 17, 22, 11, 48, 18}; What I wanted to do was to find the duplicate values, and print them. So my way of doing this was to convert to ArrayList , then to Set and use a stream on the Set . ArrayList<Integer> list = new ArrayList<>(array.length); for (int i = 0; i < array.length; i++) { list.add(array[i]); } Set<Integer> dup = new HashSet<>(list); I then used a stream to loop through it and print the values using

Java method reference throws NPE

こ雲淡風輕ζ 提交于 2020-01-23 06:28:05
问题 So I got a class public class MenuBar extends JMenuBar { MenuBarController controller; public MenuBar() { JMenu menu = new JMenu("File"); menu.add(createMenuItem("Report", controller::writeReport)); menu.add(createMenuItem("Save", controller::save)); menu.add(createMenuItem("Import", controller::importFile)); menu.add(createMenuItem("Clear DB", controller::clearDatabase)); add(menu); } public void setController(MenuBarController controller) { this.controller = controller; } }