alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (spec-t3896.scala)

This example Scala source code file (spec-t3896.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

array, atomic, atomic, atomicboolean, atomicboolean, boolean, boolean, r, t, t, test, unit

The Scala spec-t3896.scala source code

// see ticket #3896. Tests interaction between overloading, specialization and default params
trait Atomic[@specialized(Boolean) T] {
  def x: T
  
  // crash depends on the overloading: if second method is "g", no crash.
  def f(fn: T => T): Boolean = f(fn(x))
  def f[R](a: T, b: R = true) = b
}
class AtomicBoolean(val x: Boolean) extends Atomic[Boolean]

object Test {
  def main(args: Array[String]): Unit = {
    val e = new AtomicBoolean(false)
    val x = e.f( (a : Boolean) => !a ) // ok
    println( e.f( (a : Boolean) => !a ) toString ) // ok
    println( e.f( (a : Boolean) => !a) ) // compiler crash
    
    println(runtime.BoxesRunTime.integerBoxCount)
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala spec-t3896.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.