函数语法
This commit is contained in:
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# use glob syntax.
|
||||||
|
syntax: glob
|
||||||
|
*.ser
|
||||||
|
*.class
|
||||||
|
*~
|
||||||
|
*.bak
|
||||||
|
#*.off
|
||||||
|
*.old
|
||||||
|
|
||||||
|
# eclipse conf file
|
||||||
|
.settings
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.manager
|
||||||
|
.scala_dependencies
|
||||||
|
|
||||||
|
# idea
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
# building
|
||||||
|
target
|
||||||
|
build
|
||||||
|
null
|
||||||
|
tmp*
|
||||||
|
temp*
|
||||||
|
dist
|
||||||
|
test-output
|
||||||
|
build.log
|
||||||
|
|
||||||
|
# other scm
|
||||||
|
.svn
|
||||||
|
.CVS
|
||||||
|
.hg*
|
||||||
|
|
||||||
|
# switch to regexp syntax.
|
||||||
|
# syntax: regexp
|
||||||
|
# ^\.pc/
|
||||||
|
|
||||||
|
#SHITTY output not in target directory
|
||||||
|
build.log
|
||||||
73
pom.xml
Normal file
73
pom.xml
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>top.fjy8018</groupId>
|
||||||
|
<artifactId>helloscala</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>${project.artifactId}</name>
|
||||||
|
<description>My wonderfull scala app</description>
|
||||||
|
<inceptionYear>2010</inceptionYear>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>My License</name>
|
||||||
|
<url>http://....</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<scala.version>2.11.8</scala.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.scala-lang</groupId>
|
||||||
|
<artifactId>scala-library</artifactId>
|
||||||
|
<version>${scala.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src/main/scala</sourceDirectory>
|
||||||
|
<testSourceDirectory>src/test/scala</testSourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.scala-tools</groupId>
|
||||||
|
<artifactId>maven-scala-plugin</artifactId>
|
||||||
|
<version>2.15.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<args>
|
||||||
|
<arg>-make:transitive</arg>
|
||||||
|
<arg>-dependencyfile</arg>
|
||||||
|
<arg>${project.build.directory}/.scala_dependencies</arg>
|
||||||
|
</args>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<configuration>
|
||||||
|
<useFile>false</useFile>
|
||||||
|
<disableXmlReport>true</disableXmlReport>
|
||||||
|
<!-- If you have classpath issue like NoDefClassError,... -->
|
||||||
|
<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
|
||||||
|
<includes>
|
||||||
|
<include>**/*Test.*</include>
|
||||||
|
<include>**/*Suite.*</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
15
src/main/scala/top/fjy8018/App.scala
Normal file
15
src/main/scala/top/fjy8018/App.scala
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package top.fjy8018
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ${user.name}
|
||||||
|
*/
|
||||||
|
object App {
|
||||||
|
|
||||||
|
def foo(x : Array[String]) = x.foldLeft("")((a,b) => a + b)
|
||||||
|
|
||||||
|
def main(args : Array[String]) {
|
||||||
|
println( "Hello World!" )
|
||||||
|
println("concat arguments = " + foo(args))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
src/main/scala/top/fjy8018/scala/FunctionApp.scala
Normal file
32
src/main/scala/top/fjy8018/scala/FunctionApp.scala
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package top.fjy8018.scala
|
||||||
|
|
||||||
|
/**
|
||||||
|
* F嘉阳
|
||||||
|
* 2018-11-25 20:21
|
||||||
|
*/
|
||||||
|
object FunctionApp {
|
||||||
|
def main(args: Array[String]): Unit = {
|
||||||
|
println(add(1,2))
|
||||||
|
|
||||||
|
println(sum(3,4))
|
||||||
|
|
||||||
|
// 调用无参方法可以不加括号
|
||||||
|
printHello
|
||||||
|
}
|
||||||
|
|
||||||
|
def add(x:Int,y:Int):Int={
|
||||||
|
// 函数最后一行为返回值
|
||||||
|
x+y
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 函数体只有一行可以省略括号,返回值scala会自动进行类型推断
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
def sum(x:Int,y:Int)= x + y
|
||||||
|
|
||||||
|
def printHello()= println("Hello world!")
|
||||||
|
|
||||||
|
}
|
||||||
7
src/main/scala/top/fjy8018/scala/HelloWorld.scala
Normal file
7
src/main/scala/top/fjy8018/scala/HelloWorld.scala
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package top.fjy8018.scala
|
||||||
|
|
||||||
|
object HelloWorld {
|
||||||
|
def main(args: Array[String]): Unit = {
|
||||||
|
println("Hello world")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user