Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synthetic Function "##" in scala

Tags:

scala

I recently saw some code like this code:

val x: Any = "a"
val y = x.## // y: Int = 97

Well, ok the output is just the ASCI value of 'a', but lets have a look at

List(1,2).## // Int = 985731359
List(1,2).toString.## // Int = 1063384434

My IDE tells about '##' that it is a 'Synthetic Function'. So what is ## doing and what is a Synthetic Function?

like image 762
filthysocks Avatar asked Aug 17 '15 15:08

filthysocks


People also ask

What is normal liver function?

Normal blood test results for typical liver function tests include: ALT. 7 to 55 units per liter (U/L) AST. 8 to 48 U/L. ALP. 40 to 129 U/L.

What does it mean when AST and ALT are high?

If you have high levels of AST and/or ALT, it may mean that you have some type of liver damage. You may also have an AST test as part of a group of liver function tests that measure ALT, and other enzymes, proteins, and substances in the liver.

When should I worry about ALT?

What ALT level is considered high? The upper limit of normal for ALT is 55 IU/L. When an ALT level is double to triple the upper limit of normal, it is considered mildly elevated. Severely elevated ALT levels found in liver disease are often 50 times the upper limit of normal.

How is synthetic liver function measured?

The common tests that assess liver synthetic function are albumin and prothrombin time or INR.

What is synthetic function?

Synthetic function. The tests of synthetic function in the liver include prothrombin time (PT)/international normalized ratio (INR), platelet count and albumin level. Abnormal results indicate disease that has caused loss of proteins or inability to synthesize proteins.


1 Answers

It's basically an alias of hashCode, with a couple of notable exceptions that make it somewhat safer:

Equivalent to x.hashCode except for boxed numeric types and null. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For null returns a hashcode where null.hashCode throws a NullPointerException.

(source: https://www.scala-lang.org/api/current/scala/Any.html###:Int)

Examples:

normal value

scala> val x: Any = "a"
x: Any = a

scala> x.hashCode
res2: Int = 97

scala> x.##
res3: Int = 97

null value

scala> null.hashCode
java.lang.NullPointerException
  ... 33 elided

scala> null.##
res5: Int = 0

A synthetic field, instead, is a field generated by the compiler to work around the underlying JVM limitations, especially when dealing with inner anonymous classes, a concept extraneous to the JVM.

Here's a good explanation of what it means in details: http://javapapers.com/core-java/java-synthetic-class-method-field/

like image 110
Gabriele Petronella Avatar answered Oct 06 '22 04:10

Gabriele Petronella