[
https://issues.apache.org/jira/browse/GROOVY-4056?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Daniel Sun reassigned GROOVY-4056:
----------------------------------
Assignee: Daniel Sun
> Scope problem with anonymous classes
> ------------------------------------
>
> Key: GROOVY-4056
> URL: https://issues.apache.org/jira/browse/GROOVY-4056
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Environment: Ubuntu Karmic , OpenJDK , Groovy Trunk 2010-02-14
> 11:28+00:00
> Reporter: Dr. Russel Winder
> Assignee: Daniel Sun
> Priority: Major
>
> In the code fragment:
> {code}
> for ( int i = 0 ; i < numberOfTasks ; ++i ) {
> final int taskId = i
> processes[taskId] = new CSProcess ( ) {
> public void run ( ) {
> double sum = 0.0 ;
> final long start = 1 + taskId * sliceSize
> final long end = ( taskId + 1 ) * sliceSize
> for ( long j = start ; j <= end ; ++j ) {
> final double x = ( j - 0.5d ) * delta
> sum += 1.0d / ( 1.0d + x * x )
> }
> channels[taskId].out ( ).write ( sum )
> }
> }
> }
> {code}
> The outer loop uses i and in Java the loop in the run method uses i as well
> since there is no scope conflict. In Groovy, as noted above you cannot use i
> in the run method of the anonymous class as it is reported as a scoping
> violation.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)