接上篇的资源注解
我们来看下接下来的注解
@ActionBar.NavigationMode public abstract int getNavigationMode();
这种对应的就是返回指定对象的注解方式。
接下来在看一种
@WorkerThread
protected abstract Result doInBackground(Params... params);
/**
* Runs on the UI thread before {@link #doInBackground}.
*
* @see #onPostExecute
* @see #doInBackground
*/
@MainThread
protected void onPreExecute() {
}
@SuppressWarnings({"UnusedDeclaration"})
@MainThread
protected void onPostExecute(Result result) {
}
这三种注解,相信大家更熟悉AsynTask的三个主要方法,每个方法上面都有一个注解,这种注解方式称为线程注解。
下面我们再来看一种注解 ----->范围注解
范围注解大概有三种类型
- @Size:对于类似数组、集合和字符串之类的参数,我们可以使用@Size注解来表示这些参数的大小。
@Size(min=1)//可以表示集合不能为空
@Size(max=10)//可以表示字符串最大字符个数是23
@Size(2)//可以表示数组元素个数是2个
@Size(multiple=2)//可以表示数组大小是2的倍数
- @IntRange:参数是int或者long,用法如下
public void setTranslate(@IntRange(from = 0,to = 360) int distance){}
- @FloatRange:参数是float或者double
public void setAlpha(@FloatRange(from = 0.0,to = 1.0) float alpha){}
权限注解(接下来的函数随便写的大家不要介意啊)
@RequiresPermission(Manifest.permission.SET_WALLPAPER)
public void setWallpaper(Bitmap bitmap) throws IOException{}
@RequiresPermission.Read(@RequiresPermission(READ_PATH))
public final File file=new File("../sd/a.png");
//介绍下anyOf是两者中最少要有个的意思
@RequiresPermission(anyOf = {Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION})
public void setWallpaper(Bitmap bitmap) throws IOException{}
//介绍下allOf是两者中都需要的意思
@RequiresPermission(allOf = {Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION})
public void setWallpaper(Bitmap bitmap) throws IOException{}
重写函数注解
当我们的一些api允许调用者重写,但必须调用被重写的函数的时候我们可以这样设置
@CallSuper
public void onFramCreate(@Nullable Bundle bundle){}
当然还有许多的注解我不一一举例了,大家可以在看源码的时候多注意一些存在的注解,这里再给大家列几个
@Keep (针对混淆的) @VisibleForTesting(针对单元测试的)
1581

被折叠的 条评论
为什么被折叠?



