Java 斯卡拉的杰尼茨地狱世界
我正在尝试从Scala运行HelloWorld示例Java 斯卡拉的杰尼茨地狱世界,java,scala,lambda,jenetics,Java,Scala,Lambda,Jenetics,我正在尝试从Scala运行HelloWorld示例 import org.jenetics.{BitChromosome, BitGene, Genotype} import org.jenetics.engine.{Engine, EvolutionResult} object BitCounting extends App { val genotypeFactory = Genotype.of(BitChromosome.of(128, 0.5)) val fitness: j
import org.jenetics.{BitChromosome, BitGene, Genotype}
import org.jenetics.engine.{Engine, EvolutionResult}
object BitCounting extends App {
val genotypeFactory = Genotype.of(BitChromosome.of(128, 0.5))
val fitness: java.util.function.Function[Genotype[BitGene], Int] = new java.util.function.Function[Genotype[BitGene], Int] {
override def apply(genotype: Genotype[BitGene]): Int = genotype.asInstanceOf[BitChromosome].bitCount()
}
val engine = Engine.builder(fitness, genotypeFactory).build()
val result = engine
.stream()
.limit(100)
.collect(EvolutionResult.toBestGenotype[BitGene, Int])
println(s"Hello world:\n$result")
}
我在初始化引擎的那一行得到一个编译错误。编译器抱怨说
不存在符合标准类型的发动机制造商。有人能解释为什么吗 好的,问题是Engine.builder希望它的第二个类型参数有一个可比较的上限,因为Scalas Int没有实现这个接口,所以上面的代码没有编译也就不足为奇了 可能的解决方案之一是使用java.lang.Integer而不是scala.Int