Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a variable named 'type' in Play/Scala?

I want to declare a variable with name 'type' in a Play/Scala application, since my data has this field name and I'm using JSON transforms. It just makes more sense.

Fortunately I could just rename the field, but still curious if there is a way to make the compiler ignore the type reserved word when declaring variables.

like image 530
jmend Avatar asked Sep 20 '13 01:09

jmend


People also ask

How to declare the variable in Scala?

The variable is declared with the following syntax in Scala as follows: val or val variable_name: variable_datatype = value; In the above syntax, the variable can be defined in one of two ways by using either the 'var' or 'val' keyword. It consists of 'variable_name' as your new variable, followed by a colon.

How do I declare a global variable in Scala?

Since your run() function does not take parameters, the contents of value can also be computed without it. Show activity on this post. you can add java classes in Scala , so you can create a class and put your variables in static { } method and you can get access using private get methods .

How do you find the datatype of a variable in Scala?

Use the getClass Method in Scala The getClass method in Scala is used to get the class of the Scala object. We can use this method to get the type of a variable.


1 Answers

Use backticks:

var `type` = 42 
like image 159
joescii Avatar answered Sep 29 '22 07:09

joescii