Can you make an alias for another variable in scala?

Is it possible to create an alias for an array element in scala? The code below will not work, but something like that.

var str=new ArrayBuffer[String](10) def alias = str(1) alias="test" print(alias) 

Below is the code and basically what I want to do with the code above. But I do not want to type str (ALIAS) every time I use this variable. I want a shorter name

 var str=new ArrayBuffer[String](10) val ALIAS=1 str(ALIAS) = "test" print(str(ALIAS)) 
+4
source share
1 answer

Just use the standard setter syntax:

 var str= Array("a", "b", "c") def alias = str(1) def alias_=(s: String) { str(1) = s } alias = "test" print(alias) 
+4
source

Source: https://habr.com/ru/post/1400649/


All Articles