JAVA common bug

Arrays.asList()

  1. Description: This method is to convert the object into a set of arrays.
  2. Precautions:
    1. Since the collection element asList arises directly as an array reference parameter, when the collection changes or external array, an array of set change synchronously.
    2. As the collection asList produced not rewrite add, remove and so on, so it calls the parent class AbstractList, while the parent class is thrown exception information.
    3. Although the return of the List interface, but the implementation class using java.util.arrays.ArrayList class. Instead java.util.ArrayList class.
  3. Solution: Convert over the list as a constructor parameter of the ArrayList.

maven package, jdk new syntax error characteristics

  1. Description: Using maven package, development idea does not complain, but after packing, run jar error.
  2. solution
    1. the idea being given, jdk new syntax error, File-> project Structure -> project, set project jdk and project language level.
    2. After being given maven labeled jar, you need to configure maven compiler plugin.
<build>
	<plugins>
		<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
						<configuraion>
								<source>1.8</source>
								<target>1.8</target>
						</configuration>
		</plugin>
	</plugins>
</build>

Guess you like

Origin blog.csdn.net/weixin_38608626/article/details/91415050