- 博客(12)
- 收藏
- 关注
原创 Kotlin Lambda
always in curly braces{x: Int, y: Int -> x + y}if a lambda is the last argument in a function call, it can be placed after the parentheseslist.maxByOrNull ({ it: Person -> it.age })list.maxByOrNull () { it: Person -> it.age }if the lambda is.
2021-04-06 15:39:24
215
原创 Android 服务绑定
服务绑定模板服务端定义Service,实现onBind方法,返回IBinder对象。返回的IBinder对象按客户端的需求,定义API给客户端调用客户端调用bindService,传入ServiceConnection(异步回调对象)定义ServiceConnection,实现onServiceConnected方法,通过服务端返回的IBinder对象,将IBinder对象强制转换成与服务端约定的对象,调用其中的方法public class Service { public IB
2020-12-18 18:16:41
504
原创 UML类图之类间关系
关联public class Brand {}public class Car { private Brand brand;}#mermaid-svg-djzvuggNxRBdyOZy .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-djzvuggNxRBdyOZy .label text{f
2020-12-17 19:30:41
200
原创 Android Notification基本创建过程
注册通知分类Android 8.0之后的版本,要求消息必须指定notification channel,因此在app启动之后,要注册Channelif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(id, name, importance); // you can't change any channel prop
2020-12-16 18:22:35
490
原创 Android Looper消息处理机制
LooperLooper是线程级别的变量,Looper与线程是一对一的关系。Looper.prepare会new一个Looper对象,并与当前线程绑定,如果当前线程已经与某一个Looper对象绑定,再次调用Looper.prepare()会抛出异常;在不同的线程调用Looper.myLooper(),会获取到不同的Looper;在任意代码位置调用Looper.myLooper(),只要是相同的线程,就会获取到相同的LooperLooper.loop()会使当前线程阻塞(死循环获取消息并处理)H
2020-12-15 11:07:23
361
原创 Thread和ThreadPoolExecutor
Thread原始的多线程,有两种方式拉起任务直接在Thread中实现run方法,因为Thread本身也是Runnablepublic class MyThread extends Thread { @Override public void run() { System.out.println("MyThread.run()"); }...
2018-07-13 10:20:13
668
转载 【转】深入探讨 Java 类加载器
原文地址: https://www.ibm.com/developerworks/cn/java/j-lo-classloader/index.html#icomments类加载器是 Java 语言的一个创新,也是 Java 语言流行的重要原因之一。它使得 Java 类可以被动态加载到 Java 虚拟机中并执行。类加载器从 JDK 1.0 就出现了,最初是为了满足 Java Applet 的需...
2018-05-24 17:13:38
176
转载 java 7新增机制——自动关闭资源的try语句
自动关闭资源介绍 Java 7增强了try语句的功能——它允许在try关键字后跟一对圆括号,圆括号可以声明,初始化一个或多个资源,此处的资源指得是那些必须在程序结束时必须关闭的资源(比如数据库连接,网络连接等),try语句在该语句结束时自动关闭这些资源。 为了保证try语句可以正常关闭资源,这些资源实现类必须实现Closeable或AutoCloseable接口,实现这些类就必须实现clos...
2018-02-26 17:06:00
1005
转载 在Java里处理文件的技巧
从URL转换为File的方法:先判断URL是否是 file: 开头的用 new File(url.toURI()); 来转换为File注意,因为url当有空格时,会被转义为%20,所以要转换为URL,再转为File。另外要注意处理这个转义时不能使用URLDecoder。参考:http://stackoverflow.com/a/17870390写这篇Blog,主要是因为看到...
2018-02-26 16:59:48
208
原创 Class以及ClassLoader的getResource与getResourceAsStream
Class.getResource与ClassLoader.getResourcceClass.getResource最终也是调用ClassLoader.getResource,Class.getResource就多了一个resolveNamepublic java.net.URL getResource(String name) { name = resolveName(...
2018-02-09 17:18:24
429
原创 Introduction to the Spring IoC container and beans
什么是IOC Container The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container. The BeanFactory interface provides an advanced configura
2018-01-07 23:23:06
212
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人