Suppose I have the following
class SimpleClass (myInt: Int, myString: String) { }
What is wrong with the following?
val mySimple = new SimpleClass(1, "hi") println(mySimple.myInt)
In Scala, an object of a class is created using the new keyword. The syntax of creating object in Scala is: Syntax: var obj = new Dog();
Difference Between Scala Classes and Objects Definition: A class is defined with the class keyword while an object is defined using the object keyword. Also, whereas a class can take parameters, an object can't take any parameter. Instantiation: To instantiate a regular class, we use the new keyword.
POJO stands for Plain Old Java Object. It is an ordinary Java object, not bound by any special restriction other than those forced by the Java Language Specification and not requiring any classpath. POJOs are used for increasing the readability and re-usability of a program.
If you want the contructor parameters to be available as fields of the class, you have to declare them as vals or vars:
class SimpleClass (val myInt: Int, val myString: String) { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With