List of things from Java that we now happily say goodbye to after Scala

I need a list form of what Java's perverse things are history and by what Scala function it was replaced.

I have to admit that I am new to Scala, so I cannot contribute much. But I feel this list will be useful both for me and for others to fully appreciate Scala

For example, we use the keyword "val" and this makes the value unchanged after initialization. In Java, we had to introduce an object type, as well as the final keyword. Scala frees us from this pain.

Concurrency support is clearly better in Scala, but I'm not looking for this. This is too big a function that can be ignored. I am looking for finer details that are at least insignificant and will have a good effect.

Some areas: type systems, exception handling, regular expressions, OOPS functions, syntactic sugar, etc.

+5
source share
8 answers

One thing that I like is to write something like:

case class Person(name: String, age: Int)

Instead:

class Person {

  private String name;
  private int age;

  public Person(String name, int age) {
    this.name=name;
    this.age=age;
  }

  public String getName() {
      return name;
  }

  public int getAge{
      return age;
  }

  public String toString() { 
      return String.format("Person(%s, %d)", name, age);
  }

  public boolean equals(Object other) {
      if (other == this) 
          return true;
      if (other.getClass() != getClass())
          return false;
      Person p = (Person) other;
      return getName().equals(p.getName()) && getAge().equals(p.getAge());
  }

  public int hashCode() {
      int h = getName().hashCode();
      h = 37 * h + getAge(); //or whatever it is!
      return h;
  }
}
+8
source
  • Null left (mostly) in Scala
  • For expressions
  • Covariant and contravariant generic generics
  • infix operators / methods ( a + b, list map f)
  • Pattern matching
  • implicit type conversions
  • static gone (with object)
  • support for powerful packages (nested packages)

But since each function has its consequences, it is part of the design when you need to use:

  • for expression vs map / flatMap / filter / ...
  • pattern matching and polymorphism
  • Infix vs. Method Call Syntax

.

. Scala - , .

+6

, Scala:

  • - , .
  • , .. ( Scala java), - , .

, , - ( ++), , ,

+4
+4

Scala 2.8 , ...

Scala :

  • /
  • -

:

  • - , :)
  • -. , .
  • /case - , , /

Java

  • , .
  • Singletons - -,
  • - - <? T >

  • XML-

. http://www.artima.com/weblogs/viewpost.jsp?thread=275983

+2

, , . .

0

.

Scala JVM, concurrency ( VM) Java. , , Java threads, , Java.

, Java .

0

I look forward to the optionally named parameters in 2.8. They will facilitate self-documenting code on immutable objects, since you can use parameter names when calling the constructor.

In addition, copying in class classes in 2.8 will make it easier to implement copy-to-change objects, as will immutable collections already in Scala.

0
source

All Articles