2 messages in org.codehaus.groovy.user[groovy-user] Porting a java class to...| From | Sent On | Attachments |
|---|---|---|
| st.clair | 29 Mar 2008 13:05 | |
| Adam Rinehart | 03 Apr 2008 14:04 |
| Subject: | [groovy-user] Porting a java class to groovy![]() |
|---|---|
| From: | st.clair (st_c...@flowja.com) |
| Date: | 03/29/2008 01:05:52 PM |
| List: | org.codehaus.groovy.user |
Hello,
I have the following class:
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadId { // Atomic integer containing the next thread ID to be assigned private static final AtomicInteger nextId = new AtomicInteger(0);
// Thread local variable containing each thread's ID private static final ThreadLocal<Integer> threadId = new ThreadLocal<Integer>() { @Override protected Integer initialValue() { return nextId.getAndIncrement();
} }
// Returns the current thread's unique ID, assigning it if necessary public static int get() { System.out.println( "Thread ID: " + threadId.get()); return threadId.get(); }
public static void main( String[] args ) {
new ThreadId().get();
}
}
What is the groovy equivlent of this java construct in th above class?:
// Thread local variable containing each thread's ID private static final ThreadLocal<Integer> threadId = new ThreadLocal<Integer>() { @Override protected Integer initialValue() { return nextId.getAndIncrement();
} }
I am asking because no matter what I tried, Groovy does not recoginze the method initialValue().
Thanks.
--
View this message in context:
http://www.nabble.com/Porting-a-java-class-to-groovy-tp16373926p16373926.html
Sent from the groovy - user mailing list archive at Nabble.com.
--------------------------------------------------------------------- To unsubscribe from this list, please visit:




