how can I import the following package:
org.hibernate.type.StringType
in Scala? If I do:
import org.hibernate.type.StringType
"type" is recognized as a keyword. This is the second time I have run into this in two days. My last solution was the change my (Java) package name. This is no longer a valid solution!
Here is the message from Scala IDE:
<error> is not a member of org{org.type}.hibernate{org.hibernate.type}
Importation in Scala is a mechanism that enables more direct reference of different entities such as packages, classes, objects, instances, fields and methods. The concept of importing the code is more flexible in scala than Java or C++. The import statements can be anywhere.
Click on file, new then scala project and give it a name. To define a package in Scala you use the keyword package that is then followed by name of the package. To package your code you create a Scala object (. scala) and place it there then store it in your preferred folder in project structure.
Scala provides package objects as a convenient container shared across an entire package. Package objects can contain arbitrary definitions, not just variable and method definitions. For instance, they are frequently used to hold package-wide type aliases and implicit conversions.
Wrap the keyword with backquotes:
import org.hibernate.`type`.StringType
This trick also works when calling methods, which names are keywords in Scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With