2015-05-15 2 views
4

Использование библиотеки генетических алгоритмов jenetics, но я почти уверен, что она не зависит от проблемы. Кажется, что Java не понимает выражение двойной двоеточия, которое было введено в Java 8. Java 8 установлена, и Gradle использует ее.Статическая функция как параметр (: :) вызывает ошибки

Сложение неудачно из-за выражения двойного двоеточия в следующем классе:

package gen; 

import org.jenetics.BitChromosome; 
import org.jenetics.BitGene; 
import org.jenetics.Genotype; 
import org.jenetics.engine.Engine; 
import org.jenetics.engine.EvolutionResult; 

public class HelloWorld { 
    // 2.) Definition of the fitness function. 
    private static Integer eval(Genotype<BitGene> gt) { 
     return ((BitChromosome)gt.getChromosome()).bitCount(); 
    } 

    public static void main(String[] args) { 
     // 1.) Define the genotype (factory) suitable 
     //  for the problem. 
     Factory<Genotype<BitGene>> gtf = Genotype.of(BitChromosome.of(10, 0.5)); 

     // 3.) Create the execution environment. 
     Engine<BitGene, Integer> engine = Engine.builder(HelloWorld::eval, gtf).build(); 

     // 4.) Start the execution (evolution) and 
     //  collect the result. 
     // Genotype<BitGene> result = engine.stream().limit(100).collect(EvolutionResult.toBestGenotype()); 

     // System.out.println("Hello World:\n" + result); 
    } 
} 

дает Gradle вывод:

[email protected]:~/workspace/react_gen $ ./gradlew build 
:compileJava 
/home/russell/workspace/react_gen/src/main/java/gen/HelloWorld.java:21: error: ')' expected 
     Engine<BitGene, Integer> engine = Engine.builder(HelloWorld::main, gtf).build(); 
                   ^
/home/russell/workspace/react_gen/src/main/java/gen/HelloWorld.java:21: error: illegal start of expression 
     Engine<BitGene, Integer> engine = Engine.builder(HelloWorld::main, gtf).build(); 
                    ^
/home/russell/workspace/react_gen/src/main/java/gen/HelloWorld.java:21: error: ';' expected 
     Engine<BitGene, Integer> engine = Engine.builder(HelloWorld::main, gtf).build(); 
                      ^
3 errors 
:compileJava FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':compileJava'. 
> Compilation failed; see the compiler error output for details. 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 3.077 secs 

ответ

3

мне нужно добавить:

compileJava { 
    sourceCompatibility: '1.8' 
    targetCompatibility: '1.8' 
} 

в моем build.gradle, после apply plugin: 'java'

Source

Смежные вопросы