2021 2023年寒假學習進度08

2022-09-08 09:57:09 字數 1687 閱讀 6707

今天繼續學習scala

今天主要了解了泛型的使用,並且學習了vue,後續會總結vue的學習

1 協變和逆變

1)語法

class mylist[+t]

class mylist[-t]

class mylist[t] //不變

2)說明

協變:son 是 father 的子類,則 mylist[son] 也作為 mylist[father]的「子類」。

逆變:son 是 father 的子類,則 mylist[son]作為 mylist[father]的「父類」。

不變:son 是 father 的子類,則 mylist[father]與 mylist[son]「無父子關係」。

3)實操

//泛型模板

//class mylist{}

//不變

//class mylist[t]{}

//協變

//class mylist[+t]{}

//逆變

//class mylist[-t]{}

class parent{}

class child extends parent{}

class subchild extends child{}

object scala_testgeneric

}2 泛型上下限

1)語法

class personlist[t <: person]

class personlist[t >: person]

2)說明

泛型的上下限的作用是對傳入的泛型進行限定。

3)實操

class parent{}

class child extends parent{}

class subchild extends child{}

object scala_testgeneric  

//泛型萬用字元之上限

//def test[a <: child](a:class[a]): unit =

//泛型萬用字元之下限

//def test[a >: child](a:class[a]): unit =

//泛型萬用字元之下限 形式擴充套件

def test[a >: child](a:a): unit =

}3 上下文限定

1)語法

def f[a : b](a: a) = println(a) //等同於 def f[a](a:a)(implicit arg:b[a])=println(a)

2)說明

上下文限定是將泛型和隱式轉換的結合產物,以下兩者功能相同,使用上下文限定[a :

ordering]之後,方法內無法使用隱式引數名呼叫隱式引數,需要通過 implicitly[ordering[a]]

獲取隱式變數,如果此時無法查詢到對應型別的隱式變數,會發生出錯誤。

implicit val x = 1

val y = implicitly[int]

val z = implicitly[double]

3)實操

def f[a:ordering](a:a,b:a) =implicitly[ordering[a]].compare(a,b)

def f[a](a: a, b: a)(implicit ord: ordering[a]) = ord.compare(a, b)

2021 2023年寒假學習進度09

今天學習了scala的函式式程式設計 函式式程式設計 1 函式基礎 1.1 函式基本語法 1 基本語法 2 案例實操 需求 定義乙個函式,實現將傳入的名稱列印出來。def main args array string unit 2 函式呼叫 函式名 引數 f hello world 1.2 函式和方...

2021 2023年寒假學習進度19

今天完成了spark基礎實驗四,1 熟悉spark 的rdd 基本操作及鍵值對操作 2 熟悉使用rdd 程式設計解決實際具體問題的方法。作業系統 ubuntu16.04 spark 版本 2.1.0 請根據給定的實驗資料,在 spark shell 中通過程式設計來計算以下內容 1 該系總共有多少學...

寒假學習進度

今天就是踐行spark的安裝了。安裝spark 配置檔案spark env.sh 驗證spark是否安裝成功。grep 命令進行過濾。下面是關於hdfs的命令 上傳檔案 hdfs dfs put src dest 從本地的src位置上傳到hdfs的dest位置,src可以有多個,空格隔開 複製檔案 ...