Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing Java code in Scala program?

Tags:

scala

Is this allowed in Scala code:

DomNode node = node.getFirstChild()

where DomNode is Java type from external java library and getFirstChild() is defined on DomNode type.

I am porting existing java program to scala and it would be very convenient if I leave original java declerations as is to minimize porting efforts.

like image 599
ace Avatar asked Jun 15 '11 12:06

ace


1 Answers

You can use Java classes in a Scala program, but you would ofcourse have to use Scala syntax:

val node: DomNode = node.getFirstChild()

You cannot use Java syntax in the form Type variableName.

edit (thanks to ericacm) - You can also just specify

val node = node.getFirstChild()

so you don't have to specify the type of node explicitly; you can let Scala infer the type.

like image 79
Jesper Avatar answered Oct 05 '22 09:10

Jesper