4

Using the jenetics Genetic Algorithm library, but I'm almost positive that it is independent of the issue. It seems as though Java is not understanding the double-colon expression, which was introduced in Java 8. Java 8 is installed and Gradle is using it.

Build is unsuccessful due to the double colon expression in the following class:

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);
    }
}

Gives Gradle output:

russell@Ubuntu-LTS:~/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
beatngu13
  • 7,201
  • 6
  • 37
  • 66
Russell Hueske
  • 151
  • 2
  • 11

1 Answers1

3

I needed to add:

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

in my build.gradle, after apply plugin: 'java'

Source

Russell Hueske
  • 151
  • 2
  • 11