In Scala, a programming abstraction is implemented which is called as Uniform Access Principle, which states that the annotations utilized to retrieve a property of a Class is equivalent for both methods and variables. This principle was imposed forward by Bertrand Meyer. The principle simply means that the notation used to access a feature of a class shouldn’t differ depending on whether it’s a method or an attribute .
Some points to note:
- Using this Principle attributes and functions with no parameters can be accessed by identical syntax.
- The definition of a function with no parameters can be transformed to “var” or vice-versa.
- This Principle is more aligned to the object oriented programming.
Now, We know that the length of an array is a variable and length of a string is a method in the Class “String” but we accessed both of them in same way.
Here, also a variable and a method both are accessed in a same manner.
- Access Modifiers in Scala
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala Map
- Set in Scala | Set-2
- Set in Scala | Set-1
- Scala | Either
- Scala Int >>>(x: Int) method with example
- Scala this keyword
- Scala Int >>(x: Int) method with example
- Scala | Value Classes
- Scala Int %(x: Int) method with example
- Scala Int abs() method with example
- Scala ListBuffer
- Scala Int >(x: Int) method with example
- Scala Int <<(x: Int) method with example
- Scala Byte +(x: Int): Int
- Scala Int ^(x: Int) method with example
- Scala Int >=(x: Int) method with example
- Scala Int &(x: Int) method with example
- Scala Int +(x: Int) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.