This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyArray[A:ClassManifest:Nothing_=!=](size: Int) { | |
val array = new Array[A](size) | |
} | |
trait Nothing_=!=[A] | |
object MyArray { | |
implicit val anyIsNotNothing: Nothing_=!=[Any] = null | |
implicit def anyValIsNotNothing: Nothing_=!=[AnyVal] = null | |
implicit def refTypeIsNotNothing[A >: Null]: Nothing_=!=[A] = null | |
implicit def byteIsNotNothing: Nothing_=!=[Byte] = null | |
implicit def shortIsNotNothing: Nothing_=!=[Short] = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Factorial { | |
def fact(n: Int) = (1 to n).foldLeft(1)(_*_) | |
def main(args: Array[String]) = { | |
val n = if(args.length == 0) 1 else args(0).toInt | |
1 to n foreach {i => println(i + "! = " + fact(i))} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package object stack { | |
trait StackSignature { | |
type Stack[T] | |
def empty[T]: Stack[T] | |
def push[T](s: Stack[T], e: T): Stack[T] | |
def peek[T](s: Stack[T]): T | |
def pop[T](s: Stack[T]): Stack[T] | |
def isEmpty[T](s: Stack[T]): Boolean | |
} | |
val StackModule: StackSignature = new StackSignature { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//scalac -P:continuations:enable | |
import scala.util.continuations._ | |
import scala.collection._ | |
object Generator { | |
type susp = cps[Any] | |
def make[A](body: (A => Unit @susp) => Unit @susp): Iterator[A] = new Iterator[A] { | |
val yields: A => Unit @susp = {v => | |
shift{k: (Unit => Any) => (k, v):Any } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example; | |
public class Outer { | |
public class Inner1 {} | |
public static class Inner2 {} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object K { | |
def main(args: Array[String]) { | |
println(X.N) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RichInt(n: Int) { | |
def times(f: Int => Unit): Int = { | |
0 until n foreach f | |
n | |
} | |
} | |
implicit def enrichInt(n: Int) = new RichInt(n) | |
3.times{i => | |
println(i) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait A { | |
def method(){} | |
} | |
class B extends A { | |
def method(){} // Error | |
//A.scala:6: error: overriding method method in trait A of type ()Unit; | |
// method method needs `override' modifier | |
// def method(){} // Error | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList | |
trait MyArrayList[T] extends ArrayList[T] { | |
override def add(e: T): Boolean = { | |
println("added: " + e) | |
super.add(e) | |
} | |
} | |
val list = new MyArrayList[String]{} | |
list.add("A") | |
list.add("B") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.{ArrayList => JavaArrayList, List => JavaList} | |
trait LoggableList[T] extends JavaList[T] { | |
abstract override def add(e: T): Boolean = { | |
println("added: " + e) | |
super.add(e) | |
} | |
} | |
val list = new JavaArrayList[String] with LoggableList[String] | |
list.add("A") | |
list.add("B") |