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

Scala example source code file (bug2636.scala)

This example Scala source code file (bug2636.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

a1, array, array, foo, foo2, foo3, int, int, l1, l1, string, string, test, unit

The Scala bug2636.scala source code

object Test
{
  type Foo = { def update(x: Int, value: String): Unit }
  type Foo2 = { def update(x: Int, value: String): Int }
  type Foo3 = { def update(x: Int, value: String): Array[Int] }
  
  def alen() = {
    type L1 = { def length: Int }
    def len(p: L1) = p.length
    val x: L1 = Array(1,2,3)
    len(x)
  }
  
  type A1 = { def apply(x: Int): String }
  def arrApply(a: A1, x: Int) = a(x)
  
  def main(args: Array[String]): Unit = {
    val arr = new Array[String](3)
    val p1: Foo = arr
    def a1 = p1(0) = "b"

    val p2: Foo2 = new { def update(x: Int, value: String) = { p1(1) = "o" ; 1 } }
    def a2 = p2(0) = "c"    
    
    val p3: Foo3 = new { def update(x: Int, value: String) = { p1(2) = "b" ; Array(1) } }
    def a3 = p3(10) = "hi mom"
    
    a1 ; a2 ; a3 ;

    assert(arr.mkString == "bob")
    assert(alen() == 3)
    assert(arrApply(arr, 1) == "o")
    assert(arrApply(new { def apply(x: Int) = "tom" }, -100) == "tom")
  }
}

Other Scala examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.