看到的各种方向的文章记录

57 阅读1分钟

1. Docker和虚拟机的区别

aws.amazon.com/cn/compare/…

个人认为核心区别就是VM是运行自有内核和操作系统(Runs its own kernel and operating system.)。而Docker是与底层主机内核共享资源(Shares resources with the underlying host kernel)。

内核:硬件的所有功能都是操作系统的内核完成的,内核是硬件的管理者。因此即使有硬件,内核不支持也是无法使用的。内核程序一定放在受保护的区域。

系统调用:操作系统的应用编程接口(Application Programming Interface,API)。操作系统提供给程序员使用。

2. Kotlin相关

by关键字的使用

val xx by lazy {  getXx()  } // 懒加载
  
/**  
* by关键字实现委托,核心实现不需要关注是如何实现的(ArrayList, LinkedList, HashSet都行)
* 交给传入的代理对象。不需要实现StudentArrayList, StudentLinkedList等。
* 原有的Collection接口都不需要额外override一遍然后调用代理对象students的相应方法  
* 只需要关注新增的功能即可。  
*/  
class StudentList(private val students: Collection<Student>) : Collection<Student> by students {  
    fun sortByAge() {  
        students.sortedBy { it.age }  
    }  
}  
  
data class Student(val age: Int, val name: String)

fun main() {  
    val person1 = Student(age = 2, name = "Mark")  
    val person2 = Student(age = 1, name = "Janice")  

    val sl = StudentList(arrayListOf(person1, person2))  
    sl.sortByAge()  
    sl.contains(person1)  
    println()  
}