Java代码编译问题

看代码时发现一个奇怪的问题,即一个类中定义为final的成员居然可以被其他类直接引用:


如下类ServiceRecord中定义的成员deliveredStarts,被类ActiveServices直接引用:


class ServiceRecord extends Binder {
...
    final ArrayList deliveredStarts = new ArrayList();
                            // start() arguments which been delivered.


ActiveServices中直接引用了ServiceRecord的final成员:
public class ActiveServices {...
    boolean stopServiceTokenLocked(ComponentName className, IBinder token,
            int startId) {

        ServiceRecord r = findServiceLocked(className, token, UserHandle.getCallingUserId());
        if (r != null) {
            if (startId >= 0) {
                // Asked to only stop if done with all work.  Note that
                // to avoid leaks, we will take this as dropping all
                // start items up to and including this one.
                ServiceRecord.StartItem si = r.findDeliveredStart(startId, false);
                if (si != null) {
                    while (r.deliveredStarts.size() > 0) {
                        ServiceRecord.StartItem cur = r.deliveredStarts.remove(0); //居然可以被直接引用????
                        cur.removeUriPermissionsLocked();
                        if (cur == si) {
                            break;
                        }
                    }
                }
在eclipse中定义类似代码,发现均不能直接引用final变量,只有当改变为public final后方可通过编译。因此怀疑仅在Make环境下才可以编译通过

你可能感兴趣的:(android)