<?xml version="1.0" encoding="utf-8" ?><rss version="2.0"><channel><title><![CDATA[afewnotes的博客]]></title><description><![CDATA[]]></description><link>https://blog.youkuaiyun.com/afewnotes</link><language>zh-cn</language><generator>https://blog.youkuaiyun.com/</generator><copyright><![CDATA[Copyright &copy; afewnotes]]></copyright><item><title><![CDATA[Scala Types 2]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/102865476</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/102865476</guid><author>afewnotes</author><pubDate>Fri, 01 Nov 2019 22:10:32 +0800</pubDate><description><![CDATA[存在类型


形式： forSome { type ... } 或 forSome { val ... }
主要为了兼容 Java 的通配符
示例



  Array[_]
  // 等价于
  Array[T] forSome { type T}

  Map[_, _]
  // 等价于
  Map[T, U] forSome { type T; type U &lt;: T}


类型系...]]></description><category></category></item><item><title><![CDATA[Scala Types 1]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/102808332</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/102808332</guid><author>afewnotes</author><pubDate>Tue, 29 Oct 2019 20:51:48 +0800</pubDate><description><![CDATA[在 Scala 中所有值都有一种对应的类型
单例类型


形式：value.type，返回类型 value / null
场景1：链式API调用时的类型指定



  class Super {
    def m1(t: Int) = {println(t); this}
    def m2(t: Int) = {println(t); this}
  }
  // 正常打印
  new Su...]]></description><category></category></item><item><title><![CDATA[Scala Type Parameters 2]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/102472019</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/102472019</guid><author>afewnotes</author><pubDate>Wed, 09 Oct 2019 23:16:43 +0800</pubDate><description><![CDATA[类型关系



Scala 支持在泛型类上使用型变注释，用来表示复杂类型、组合类型的子类型关系间的相关性

协变  T，变化方向相同，通常用在生产



    &gt; 假设 `A extends T`, 对于 `Clazz[ T]`，则 `Clazz[A]` 也可看做 `Clazz[T]`

    // 官网示例
    abstract class Animal {
      def...]]></description><category></category></item><item><title><![CDATA[Scala Type Parameters 1]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/102420279</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/102420279</guid><author>afewnotes</author><pubDate>Tue, 08 Oct 2019 23:30:49 +0800</pubDate><description><![CDATA[类型参数


表现形式：在名称后面以方括号表示， Array[T]
何处使用

class 中，用于定义变量、入参、返回值





    class Pair[T, S](val first: T, val second: S)
    // scala 可自动推断具体的类型
    val p = new Pair(42, "String") // Pair[Int, String]



...]]></description><category></category></item><item><title><![CDATA[Scala Future]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/102288049</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/102288049</guid><author>afewnotes</author><pubDate>Mon, 07 Oct 2019 08:46:02 +0800</pubDate><description><![CDATA[Future

scala.concurrent.Future 异步执行代码块



    import java.time._
    import scala.concurrent._
    import ExecutionContext.Implicits.global // 全局线程池
    Future {
            Thread.sleep(10000)
    ...]]></description><category></category></item><item><title><![CDATA[Scala XML]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/102287837</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/102287837</guid><author>afewnotes</author><pubDate>Mon, 07 Oct 2019 08:38:16 +0800</pubDate><description><![CDATA[XML


直接在代码中使用 XML 字面量



  val doc: Elem = &lt;html&gt;&lt;head&gt;&lt;title&gt;Test&lt;/title&gt;&lt;/head&gt;&lt;body&gt;test&lt;/body&gt;&lt;/html&gt;
  val items: NodeBuffer = &lt;li&gt;item1&lt...]]></description><category></category></item><item><title><![CDATA[Scala Collection Method]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/101906413</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/101906413</guid><author>afewnotes</author><pubDate>Wed, 02 Oct 2019 11:06:44 +0800</pubDate><description><![CDATA[接收一元函数

map 转换元素，主要应用于不可变集合





    (1 to 10).map(i =&gt; i * i)
    (1 to 10).flatMap(i =&gt; (1 to i).map(j =&gt; i * j))


transform 与 map 相同，不过用于可变集合，直接转换



    ArrayBuffer("Peter", "Paul", "M...]]></description><category></category></item><item><title><![CDATA[Scala Operators, File & RegExp]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/101829888</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/101829888</guid><author>afewnotes</author><pubDate>Tue, 01 Oct 2019 09:50:44 +0800</pubDate><description><![CDATA[Operators


Thread.yield() 反引号除了用于命名标识符，还可以在调用方法时避免冲突(yield 为 Scala 关键字，但也是 Thread 的方法)
中缀运算符(infix operators)，实际是带两个参数的方法，定义时跟普通方法一样；a to b 实际是 a.to(b)
一元运算符(unary operators)

 , -, !, ~四个可当做前缀运算符使用...]]></description><category></category></item><item><title><![CDATA[Scala Class etc. 2]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/101794130</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/101794130</guid><author>afewnotes</author><pubDate>Mon, 30 Sep 2019 21:28:59 +0800</pubDate><description><![CDATA[Higher-Order Functions


def 定义的是方法，而不是函数
函数可作为变量存在，可直接调用，也可作为值传递给其他函数
_ 后缀将普通方法变为函数: ceil _

根据上下文编译器可以自动将方法转换为函数，也可省略 _ 后缀


高阶函数，接收函数的函数
参数类型推导

匿名函数传递给其他函数或方法时，如果一直到参数类型，则可省略匿名函数的参数类型，可自动推导类型
参数只有...]]></description><category></category></item><item><title><![CDATA[Scala Class etc.]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/101718169</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/101718169</guid><author>afewnotes</author><pubDate>Sun, 29 Sep 2019 21:24:48 +0800</pubDate><description><![CDATA[Classes


一个源文件可包含多个类，每个类默认都是 public
类字段必须初始化，编译后默认是 private，自动生成 public 的 getter/setter ；Person 示例

private 字段，生成 private 的 getter/setter
val 字段，只生成 getter
private[this] 字段，不生成 getter/setter
自定义 get...]]></description><category></category></item><item><title><![CDATA[Scala Data Structure]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/101649149</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/101649149</guid><author>afewnotes</author><pubDate>Sun, 29 Sep 2019 00:02:43 +0800</pubDate><description><![CDATA[Arrays


Array 固定长度；ArrayBuffer 可变长度

arr.toBuffer, buf.toArray


初始化是不要使用 new
使用 () 访问元素
使用 for (elem  90, "c" -> 95) 创建的默认为 immutable 的 hash map
可变的 Map 需要显式指定 scala.collection.mutable.Map
创建空的 Map...]]></description><category></category></item><item><title><![CDATA[Scala Basis]]></title><link>https://blog.youkuaiyun.com/afewnotes/article/details/101648048</link><guid>https://blog.youkuaiyun.com/afewnotes/article/details/101648048</guid><author>afewnotes</author><pubDate>Sat, 28 Sep 2019 23:42:26 +0800</pubDate><description><![CDATA[基础


Scala 中数据类型也是 class

7 种数值类型: Byte, Char, Short, Int, Long, Float, and Double
Boolean 类型


原始类型与 class 类型无区别，可在数字上调用方法（隐式转换为对应的方法调用，如对 Int 操作转为 RichInt 的方法调用等）

1.toString()
1.to(10) // Range(1,2...]]></description><category></category></item></channel></rss>