我想打包maven-(多)模块,父POM包括:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我正在使用Java 1.7,属性指定如下:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<slf4j.version>1.6.1</slf4j.version>
</properties>
Run Code Online (Sandbox Code Playgroud)
Maven版本是2.2.1:
johannes@luna:~/workspace/treetank/bundles/treetank-core$ mvn -version
Apache Maven 2.2.1 (rdebian-6)
Java version: 1.7.0
Java home: /usr/lib/jvm/jdk1.7.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.0.0-14-generic" arch: "amd64" Family: "unix"
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不使用Java版本1.7.在调用时,mvn package我得到错误(例如,使用-source 7或更高版本来启用菱形运算符).你知道它为什么尝试使用1.6吗?
有效的POM是:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding> …Run Code Online (Sandbox Code Playgroud) 我想调试一个静态内部类,它实际上是一个Callable.每当我尝试在Eclipse中设置条件断点时,我都会收到断点错误:
该类型
com.sun.source.tree.Tree$Kind无法解决.它是从所需的.class文件间接引用的.
导致此错误的原因是什么?它是使用com.sun.source.tree.Tree$Kind但不提供的类/包中的错误吗?我怎么知道它是哪一堂课?我该如何解决?
一个应该正确的示例表达式是: return mRtx.getNode().getNodeKey() == 74;
我已将其更改为mRtx.getNode().getNodeKey() == 74但仍然是相同的错误.最近我发现了这个bug并且简单地使用了:
if (mRtx.getNode().getNodeKey() == 74) {
System.out.println("bla");
}
Run Code Online (Sandbox Code Playgroud)
并在"sysout"语句中设置"正常"断点,以防有人遇到同样的问题.
我正在开发一个简单的树形结构数据库,我通常通过Builder(Builder模式)设置依赖项或可选设置.现在我不确定何时使用Guice,何时使用Builder模式以及何时使用静态工厂方法而不是构造函数本身.我已经多次阅读过Effective Java,我认为它至少提到了不暴露构造函数的许多优点.是时候重读了;-)
那么,您是否知道明显可区分的案例?我不应该暴露构造函数?因此,例如在每种情况下写public static Foo getInstance(...) { return new Foo(...)}?
我想检测文件或目录是否已被删除.显然我不能使用Files.isDirectory(Path)和文件的等价物,因为文件/目录已被删除.
我想过使用两个WatchService实例来观察文件更改或目录更改,然后我知道它是文件还是目录.可悲的是,我找不到合适的方法.
编辑:我认为有关检查文件名与目录的字符串表示的任何其他解决方案都容易出错.
我正在使用Java-API,它大量使用Autoclosable-Interface,因此使用Java try-with-resources.但是在Java中您可以指定
try (res1, res2, res3...) {
...
}
Run Code Online (Sandbox Code Playgroud)
我们有办法使用多种资源吗?它看起来像众所周知的回调 - 地狱:
val database = Databases.openDatabase(dbFile)
database.use {
database.createResource(ResourceConfiguration.Builder(resPathName, config).build())
val resMgr = database.getResourceManager(ResourceManagerConfiguration.Builder(resPathName).build())
resMgr.use {
val wtx = resMgr.beginNodeWriteTrx()
wtx.use {
wtx.insertSubtreeAsFirstChild(XMLShredder.createStringReader(resFileToStore))
}
}
}
Run Code Online (Sandbox Code Playgroud) 有人知道未来Guava或Java8是否会提供受更多功能实现启发的持久性集合实现,例如在Clojure或Scala中(提供快照,由于共享树结构而进行有效修改等)?
有没有人知道好的教程,甚至是掌握位级操作的好书?我的意思是几乎清楚每个操作的作用(例如在Java中)或在哪里找到正确的文档,但我对这个主题很新,我想知道如何:
// Find a power of 2 >= initialCapacity
int capacity = 1;
while (capacity < initialCapacity)
capacity <<= 1;
Run Code Online (Sandbox Code Playgroud)
工作(复制自HashMap).我无法想象整数,长期或任何数据类型如何受位操作的影响:-(
我的意思是我不想知道各种操作,只是对于Java或Scala中的高级程序员来说,就像提供的示例一样.
另一个例子是:
/**
* Applies a supplemental hash function to a given hashCode, which
* defends against poor quality hash functions. This is critical
* because HashMap uses power-of-two length hash tables, that
* otherwise encounter collisions for hashCodes that do not differ
* in lower bits. Note: Null keys always map to hash 0, thus index …Run Code Online (Sandbox Code Playgroud) 我希望能够在两个equals-Implementations之间切换,但我不确定EquivalenceGoogle Guava 的类是否可以提供此功能.假设我有两个equals方法equalsContent()和equalsKeys()或类似的东西我想以某种方式将equals方法委托给两个私有方法之一(对于两个hashCode方法也是如此).
好吧,我不知道Equivalence抽象类和Equivalences类(静态方法)的用法是什么.
此外,您将如何实现上述所需的属性?我可以使用另一个简单地为值设置标志或枚举的方法,并使用两个抽象方法(equals(),hashCode())在枚举中实现两个equals和hash方法,并简单地调用enum.equals()或enum equals()和hashCode()方法中的.hashCode().你怎么看?
切换到Eclipse 4.2.0后,调试器似乎没有响应或非常慢.我使用的Java版本(与Eclipse中使用的相同):
johannes@luna:~/sirix$ java -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)`
Run Code Online (Sandbox Code Playgroud)
其他人遇到过同样的行为吗?
编辑:我有太多(旧的)断点(特别是在已检查和未检查的例外情况下断点特别昂贵;-))
是否可以包含Java9(或10)依赖项?因为Kotlin到目前为止只能编译到Java 8.我java.lang.UnsupportedClassVersionError明显得到一个错误,说明我所包含的JAR /依赖项中的一个类已经被更新版本的Java Runtime编译.但是我无法指定一个更新的JDK,它能够运行用旧版本编译的类(Kotlin的东西?).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>9</release>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.1</version> <!-- Use newer version of ASM -->
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
随着属性
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
Run Code Online (Sandbox Code Playgroud)
但现在我收到了错误:
"Error:Kotlin: Unknown JVM target version: 1.9
Supported versions: 1.6, 1.8"
Kotlin版本1.2.41,到目前为止,我总是可以切换到最新版本,直到它发布...
可以使用以下XML片段.然而问题java.lang.UnsupportedClassVersionError仍然存在.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it …Run Code Online (Sandbox Code Playgroud) 字节数组比较(使用简单的循环来检查每个索引)比使用更快String.equals(Object)吗?我不这么认为,但是有些人似乎更喜欢基于字节的操作而不是基于字符串的操作,包括字节数组相等检查.
在侧节点上,什么时候使用字节数组而不是字符串?您是否认为例如实施Levenshtein算法来计算两个字符串的"距离"的度量.如果它基于字节而不是字符串/字符,你认为它会加速计算吗?我不这么认为,但也许.
例如,它用于编码令牌,如https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/util/Token.java