Java的:需要一些方法来缩短这个code [英] Java: Need some way to shorten this code

查看:107
本文介绍了Java的:需要一些方法来缩短这个code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这块code,我想缩短...

  PackageManager P = context.getPackageManager();
    最后的名单,其中,PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    PackageManager亲= context.getPackageManager();
    最后的名单,其中,PackageInfo> apllprovides = pro.getInstalledPackages(PackageManager.GET_PROVIDERS);
 

我是认真恼火做到这一点一再增加新标志的权限,我需要做几次,有没有,我可以把所有的国旗相同的定义更短的方法... ???

让我这么说吧,我能做到这一点???? (当然这给出了一个错误,但类似的东西..)

  PackageManager P = context.getPackageManager();
    最后的名单,其中,PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS).addFlag(PackageManager.GET_PROVIDERS);
 

解决方案

如果它是相同的语法,C#和标志设置是否正确,你可以这样做:

  PackageManager P = context.getPackageManager();
最后的名单,其中,PackageInfo> appinstall =
    p.getInstalledPackages(PackageManager.GET_PERMISSIONS |
                                      PackageManager.GET_PROVIDERS)
 

I have this piece of code that I would like to shorten...

    PackageManager p = context.getPackageManager();
    final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    PackageManager pro = context.getPackageManager();
    final List<PackageInfo> apllprovides = pro.getInstalledPackages(PackageManager.GET_PROVIDERS);

I am seriously irritated to do this again and again to add new flag permissions, and I need to do it a couple of times, is there a shorter method in which I could put all the flags on the same definition...???

Let me put it this way, can I do this...??? (of course this gives an error, but something similar..)

    PackageManager p = context.getPackageManager();
    final List<PackageInfo> appinstall = p.getInstalledPackages(PackageManager.GET_PERMISSIONS).addFlag(PackageManager.GET_PROVIDERS);

解决方案

If it's the same syntax as C# and the flags are set properly, you could do this:

PackageManager p = context.getPackageManager(); 
final List<PackageInfo> appinstall = 
    p.getInstalledPackages(PackageManager.GET_PERMISSIONS | 
                                      PackageManager.GET_PROVIDERS)

这篇关于Java的:需要一些方法来缩短这个code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆