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

Scala example source code file (spec.scala)

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

a, a, anyref, anyref, array, array, b, b, base, baz, foo, inner, qux, withanon

The Scala spec.scala source code





class Bar[@specialized(Int, AnyRef) A](a: A) {
  val memb = a
}


class WithInner[@specialized(Int, AnyRef) A](a: A) { 
  class Inner {
    def meth = a
  }
}


class Baz[@specialized(Int, AnyRef) A, @specialized(Int, AnyRef) B] {
  def ab(a: A, b: B) = (a, b)
}


trait Base[@specialized(Int, AnyRef) A]
class Concrete[@specialized(Int, AnyRef) A] extends Base[A]


class WithAnon[@specialized(Int, AnyRef) A](a: A) {
  new AnyRef {
    def foo = a
  }
}


class Norm {
  def id[@specialized(Int, AnyRef) A](a: A) = a
}


class Qux[@specialized(AnyRef) A] {
  def memb[@specialized(AnyRef) B](a: A, b: B) = (a, b)
}


class Foo[@specialized(Int, AnyRef) A](val a: Array[A]) {
  a(0)
  
  def id(elem: A) = a(0) = elem
}


// instantiation and selection
object Test {
  def main(arg: Array[String]) {
    val f = new Foo(new Array[String](5))
    f.id("")
    
    val z = new Baz[Int, Double]
    z.ab(1, 1.0)
    
    testspec(new Array[String](5))
    testspec(new Array[Int](5))
  }
  
  def testspec[@specialized(Int, AnyRef) T](arr: Array[T]) = arr(0)
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala spec.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.