If you read scala documentation
Scala combines object-oriented(OOP) and functional programming(FP) in one
concise, high-level language.
In my opinion scala got a JVM market because java used to be only OO until java8; while you could do both OO + fp in scala.
Since fp encourages ideas like immutability, it is not ideal to use same Java libraries because Java did not offer immutability or was not practiced.
Thats why you will see engineers re-writing or porting JVM libraries using idiomatic scala; also called pure fp, instead of calling impure code.
Here's example of scala immutability;
scala> case class Customer (name: String)
defined class Customer
scala> val customer = Customer(name = "Stephen")
customer: Customer = Customer(Stephen)
scala> customer.name = "Lino"
<console>:13: error: reassignment to val
customer.name = "Lino"
^
java10 now provides some immutable data-structures like List
, Map
;
java immutable example using final
;
jshell> class Customer { final String name = "default customer"; }
| created class Customer
jshell> var customer = new Customer()
customer ==> Customer@887af79
jshell> customer.name = "Lino"
| Error:
| cannot assign a value to final variable name
| customer.name = "Lino"
| ^-----------^
Twist: since java is becoming more functional I can not tell what scala would be doing with their OO + FP philosophy?