Skip to content

Instantly share code, notes, and snippets.

View shiyifan's full-sized avatar
:octocat:
coding

Ivan shiyifan

:octocat:
coding
  • Changchun University of Science and Technology
  • China,Jilin
View GitHub Profile
@shiyifan
shiyifan / LiveData.java
Last active April 30, 2019 10:35
LiveData中调用observe需要注意的事情
@MainThread
public void observe(@NonNull LifecycleOwner owner, @NonNull Observer<? super T> observer) {
assertMainThread("observe");
if (owner.getLifecycle().getCurrentState() == DESTROYED) {
// ignore
return;
}
LifecycleBoundObserver wrapper = new LifecycleBoundObserver(owner, observer);
/*
* mObservers是一个map,key是Observer, value是ObserverWrapper,用来存放所有该LiveData对象的观察者。
@shiyifan
shiyifan / IndexRandomer.java
Last active January 17, 2019 07:17
当Spring依据“类型匹配(type-matching)”规则找到注入点(Injection Point)(例如:randomer)的多个候选Bean时,Spring会查找与注入点的变量名相同的Bean的Name属性,如果找到一个则进行注入,否则抛出异常。See Alsohttps://docs.spring.io/spring/docs/5.1.4.RELEASE/spring-framework-reference/core.html#beans-autowired-annotation-qualifiers
@Component("indexRandomer")
public class IndexRandomer implements Randomer {
@Override
public List<Integer> nextIntList(int bound, int length) {
List<Integer> list = IntStream.range(0, bound).collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
Random rnd = new Random();
List<Integer> result = new ArrayList<>(length);
for (int i = 0; i < length; i++, bound--) {
int idx = rnd.nextInt(bound);
result.add(list.get(idx));
ZZZ...
First Gist...