Static Fields

15 views
Skip to first unread message

consiliens

unread,
Jan 4, 2012, 2:01:29 PM1/4/12
to Xtend Programming Language
How does one access a qualified static field in Xtend2?

import java.io.File
String separator = File.separator // fails
String separator2 = java.io.File.separator // fails

While a wildcard static import works, it's not the same.

import static java.io.File.*
String separator3 = separator

Jason Thomas

unread,
Jan 4, 2012, 2:13:56 PM1/4/12
to xtend...@googlegroups.com
Use :: i.e. - 

val separator = File::separator 
val separator2 = java::io::File::separator

-Jason

consiliens

unread,
Jan 4, 2012, 2:25:31 PM1/4/12
to xtend...@googlegroups.com
It doesn't work.

package xtend.tutorial.basicsimport java.io.File
class Xtend01_HelloWorld {
// mismatched input 'val' expecting '}'val separator2 =
java::io::File::separator}

consiliens

unread,
Jan 4, 2012, 2:30:22 PM1/4/12
to xtend...@googlegroups.com
Gmail removed the code formatting. Here's a Gist link.

https://gist.github.com/1561606

Sebastian Zarnekow

unread,
Jan 4, 2012, 2:46:19 PM1/4/12
to xtend...@googlegroups.com
Hi,

the following is valid (since Xtend 2.2):

package xtend.tutorial.basics

class Xtend01_HelloWorld {

static String separator2 = java::io::File::separator

}

Note that type inference is currently not supported for field declarations thus you'll have to specify the type explicitly.

Regards,
Sebastian

signature.asc

consiliens

unread,
Jan 4, 2012, 4:26:04 PM1/4/12
to xtend...@googlegroups.com
Thanks for the working code and explanation.

I'm looking forward to bug 367885 being fixed so fields can be both
static and final.

Reply all
Reply to author
Forward
0 new messages