JAVA VS SCALA
POJO IN JAVA VS SCALA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| public class PostJ { private String title; private String text; private String author; public String getTitle() { return title; } public void setTitle(String title) { this .title = title; } public String getText() { return text; } public void setText(String text) { this .text = text; } public String getAuthor() { return author; } public void setAuthor(String author) { this .author = author; } }
And the Scala version.
|
Java Syntax:
------------------
<data type> <variable name> = <value> ;
int a = 10;
------------------
val <variable name> : <data type> = <value>
val a : Int = 10
val s : String = "Spark"
var is immutable.
NOTE: SCALA SUPPORTS " TYPE INFER"= automatically find the data type from value.
val a = 10;
val s= "Spark"
var <variable name> : <data type> = <value>
var is mutable.