A “hot” Observable may begin emitting items as soon as it is created, and so any observer who later subscribes to that Observable may start observing the sequence somewhere in the middle. A “cold” Observable, on the other hand, waits until an observer subscribes to it before it begins to emit items, and so such an observer is guaranteed to see the whole sequence from the beginning.官网上的解释已经比较详细了,简单点说区别就是cold会等到有observer监听之后,才会发出事件,而hot则可能随时发出事件,不顾是否有observer监听了这个observable。
这是observable继承关系的类图,cold observable属于ordinary observable,也就是图中的observable类,而hot observable则属于ConnectableObservable,值得注意的是在ConnectableObservable有一个有趣的函数connect函数,方法签名如下:
从方法的注解可以了解,这就是hot和cold observable的区别所在,还有一点值得注意的就是类图中的Subject,Subject在RX中属于既是observable又是observer,具有双面性
![张梦 > hot and cold observable > image2015-10-29 16:27:37.png](http://wiki.sankuai.com/download/attachments/361702141/image2015-10-29%2016%3A27%3A37.png?version=1&modificationDate=1446108043000&api=v2)
![张梦 > hot and cold observable > image2015-10-29 16:39:0.png](http://wiki.sankuai.com/download/attachments/361702141/image2015-10-29%2016%3A39%3A0.png?version=1&modificationDate=1446108043000&api=v2)