This file contains 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 FirstClassFunction{ | |
def main(args: Array[String]){ | |
val add = (x: Int) => { | |
val _add = (y: Int) => y + 5 | |
_add(x) | |
} | |
printf("add=%s \n", add(1)) | |
printf("add=%s \n", add(2)) | |
printf("add=%s \n", add(1)) |
This file contains 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
public class User { | |
private final long id; | |
private final String firstname; | |
private final String lastname; | |
public User(long id, String firstname, String lastname) { | |
this.id = id; |
This file contains 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
public class Car { | |
public static void main(String[] args) { | |
final Car car = new Car("blue"); | |
car.run(); | |
} | |
private static void output(String message) { | |
System.out.println(message); | |
} |
This file contains 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 Literal { | |
def main(args: Array[String]){ | |
// 整数リテラル | |
// 10進数 | |
val dec = 24 | |
println("dec:" + dec) | |
// 16進数 | |
val hex = 0x24 | |
println("hex:" + hex) |
This file contains 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 CaseClassTuple { | |
def get() = { | |
val name = new Name("清美", "椿山") | |
(Human(name, 15), name) | |
} | |
def main(args: Array[String]){ | |
val tuple = get() | |
printf("fullname_1=%s \n", tuple._1.name.fullname) |
This file contains 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
scala> val numbers = Set(1, 2, 3) | |
numbers: scala.collection.immutable.Set[Int] = Set(1, 2, 3) |
This file contains 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 Job { | |
def getName() { | |
"student" | |
} | |
} |
This file contains 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
scala> Seq(1, 2, 3).foreach(print(_)) | |
123 |
This file contains 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
scala> Seq(1, 2, 3)(2) | |
res0: Int = 3 |
This file contains 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 Option1 { | |
def main(args: Array[String]): Unit = { | |
val map = Map(1 -> "Moses", 2 -> "Lucas", 3 -> "Henderson") | |
def check(o: Option[String]) { | |
o match { | |
case Some(s) => println(s) | |
case None => println("Not exist.") | |
} |
OlderNewer