Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import package with part "type" in Scala?

Tags:

import

scala

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}
like image 355
schmmd Avatar asked Mar 11 '11 00:03

schmmd


People also ask

How do imports work in Scala?

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.

How do I use Scala packages?

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.

What is a package object Scala?

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.


1 Answers

Wrap the keyword with backquotes:

import org.hibernate.`type`.StringType

This trick also works when calling methods, which names are keywords in Scala.

like image 98
Rafał Rawicki Avatar answered Oct 19 '22 11:10

Rafał Rawicki