score:2
i don't think there is a good way to do what you want such that:
- you can neatly tie all members to an identifier (i.e. refer to the field via
swt.x
instead ofx
) - have it work both in scala and java.
- you don't have to manually forward fields.
this is a documented limitation of scala -- see access java base class's static member in scala.
in addition, i don't think the implicit route works either, because you can't treat a java class as a value: how to access a java static method from scala given a type alias for that class it resides in
probably the best way to do what you want is to manually forward the static members you need in my.package.swt
:
public class swt extends org.eclipse.swt.swt {
public static final int finalizetext = 201;
public static final int parsetext = 202;
public static int getmousedown() {
return mousedown;
}
}
if you only care about automatically forwarding members and not about the other requirements, you can use import
:
import org.eclipse.swt.swt._
table.addlistener(mousedown, periodeditlistener)
score:0
i am accepting yuzeh's answer for thoroughness, general applicability, and helpfulness, but here is what i actually did, which is slightly different:
i was very tempted by yuzeh's last suggestion for the sake of uniformity, i.e.
import org.eclipse.swt.swt._
import my.package.swt._
although as my first example snippet above inadvertently shows, swt.none
unfortunately is, so bringing it into the local namespace would conflict with option's none.
i think for now i'll just import like:
import org.eclipse.swt.swt
import my.package.{swt => myswt}
if nothing else, it is a bit more clear where the constants are coming from. there, i talked myself into believing this is better :).
Source: stackoverflow.com
Related Query
- How to enrich a Java library class that has static methods (aka enrich an object in Scala)?
- How do I write a JSON Format for an object in the Java library that doesn't have an apply method?
- How to access a Java static method from Scala given a type alias for that class it resides in
- Get static methods of a class nested in an object using Java reflection
- How to do implicitly convert to a class that has methods of the same name
- Scala object extends Java class static field
- How to discover the library that defines a class from sbt?
- How to make sure that an object of a class is marshalled automatically by Spring boot if it is a Rest controller
- How can I store a reference to a set of static Java methods from Scala?
- How to access a public static final member in a Java class from Scala?
- How to add methods that takes implicit ordering to a scala collection object
- Unit testing class that extends a trait - how do I mock and stub methods in the trait?
- Access from Java a Scala object that inherits from a generic Java base class
- How to "extend" factory methods when extending class with companion object with factory methods
- How to "reads" into a Scala Case Class given a Json object with key names that start with a capital letter
- Scala object that extends Java class
- How to get the type parameters from an abstract class that is extended by an object
- With scala play, how to convert a class that has an ObjectId to Json?
- How to pass complex Java Class Object as parameter to Scala UDF in Spark?
- how to write a class that has array of anything as member
- Scala - How to create a class with a constructor that receives an object as parameter
- How to deal with class that has too many parameters in constructor - Scala?
- using duck typing to create mixins in Scala, can i decorate existing methods in a class that has no 'knowledge' of the mixin trait?
- Instantiate a java static inner class from a scala object
- How to get the class of a trait within an object defined in scala from within a java class?
- How to invoke public static method for existing Java class instance from Scala?
- How to pass class object as a variable in Java
- How to call a Scala method that has Numeric parameter from Java
- Scala reflection: How to construct object and run its methods given 'String-type' class name and method name?
- How can I specify that a class passed in a type parameter has a certain companion object?
More Query from same tag
- PlayFramework: Render first page sample
- how to deserialize a json string that contains @@ with scala'
- "type mismatch" implementing typed Security.authenticated
- Spark SQL create an array with array values in a column
- Scala and Node.js
- How to access Annotation defined on case class field at Runtime
- Exceptions while running Spark job on EMR cluster "java.io.IOException: All datanodes are bad"
- Scala: normal functions vs tupled functions?
- Spark get all rows with same values in array in column
- How to implement tail-recursive quick sort in Scala
- How do I expand a dataframe of array of struct and filter based on the length of unique items in each row?
- How to interpret Scala's SIP notation
- Restrict values in spark dataframe to only specified values
- How to execute a set of code before and after controller tests written using PlaySpecification?
- Aggregating multiple errors
- Define method declaration which argument is a implementation type
- Create dynamic query from the Dataframe present in Spark Scala
- Safe chaining in scalaz Disjunction
- Plus One Linked List: Functional Approach
- Scala: unpacking an Object: how do I know the type
- Scalafx: create lineChart in scala
- Spark: Transpose DataFrame Without Aggregating
- scala.collection.immutable.NumericRange[UInt]?
- Scala compiler StackOverflow Error when importing project
- Packaging and Deploying Scala Applications
- Scala mutable BitSet, where are the mutating operations?
- Exception in thread "main" org.apache.spark.sql.AnalysisException: cannot resolve '`id`' given input columns: [0, 33, 385, Will];
- Could not find implicit format for parameter
- is it possible (and how) to specify an sql query on command line with spark-submit
- Why no immutable arrays in scala standard library?