Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - Java Project - Generic For Loop

I have a very simple generic for loop that is causing problems when I attempt to build the project using gradle:

for(TaskAttribute taskAttribute:task.getAttributes())
{
...
}

Task.java

protected final Set<TaskAttribute> attributes = new HashSet<TaskAttribute>();

public Set<TaskAttribute> getAttributes(){return(attributes);}

The error I am getting is that the for loop is getting Object, but requries TaskAttribute. I have my sourceCompatibility set to 1.6. Am I missing something else?

like image 268
Walter Avatar asked May 18 '26 09:05

Walter


1 Answers

In groovy you can do for loops one of two ways.

task forLoopTest {
    // print numbers 8 to 19 inclusive
    for (x in 8..19) {
    println 'this is run '+x
    }

    // print numbers 0 to 4 
    println 'now some groovy'
    for(int i = 0;i<5;i++) {
        println i
    }
}

Run on CLI:

$ gradle forLoopTest

This should out put.

this is run 8
this is run 9
this is run 10
this is run 11
this is run 12
this is run 13
this is run 14
this is run 15
this is run 16
this is run 17
this is run 18
this is run 19
0
1
2
3
4
like image 117
9716278 Avatar answered May 20 '26 23:05

9716278



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!