Java小白入门问题集锦

295 阅读1分钟

环境: IntelliJ Idea, Maven, Mac,Java 1.8

1. 不支持钻石操作符<>

报错如下:

Error:(70, 54) java: diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)

大部分的解决方案都是,在pox.xml中增加source配置,如

    <plugins>
      <plugin>
      ...
        <configuration>
          <source>1.8</source>
        </configuration>
      </plugin>
    </plugins>

或者说本地java版本太低需要升级。若增加source配置会改变原有代码。

最优解决:
定位到File->Project Structure->Project Settings,可以发现,Project和Modules的Language Level默认配置都是5,这两者都选择8及以上(需保持一致),并重启Idea即可。

参考: www.naturalborncoder.com/uncategoris…

2. JavaLaunchHelper 在两处都有实现

报错如下:

objc[6162]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java (0x1074c74c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x1075414e0). One of the two will be used. Which one is undefined.

虽报错可忽略,但对于有洁癖的人来说,处理才好。
解决: 定位IDEA菜单Help->Edit Custom Properties,无则创建,添加配置

idea.no.launcher=true

然后重启IDEA可起效。
参考: stackoverflow.com/questions/4…