简体   繁体   English

为什么用Java返回false?

[英]Why return false in Java?

I'm writing an Android app that uses an AdapterView. 我正在编写一个使用AdapterView的Android应用。 There are multiple calls to IsInFilterMode() in the AdapterView class which simply is a one line function that returns false. 在AdapterView类中有多次对IsInFilterMode()调用,这只是返回false的单行函数。 I can't override the function so I can't for the life of me figure out why this function exists if it just returns false. 我无法覆盖该函数,因此我一生都无法弄清楚为什么如果该函数返回false便存在该函数。 The description says that it returns true if it's in filter mode. 描述说,如果它处于过滤器模式,则返回true。 Here is the definition of IsInFilterMode() : 这是IsInFilterMode()的定义:

 /**
 * Indicates whether this view is in filter mode. Filter mode can for instance
 * be enabled by a user when typing on the keyboard.
 *
 * @return True if the view is in filter mode, false otherwise.
 */
boolean isInFilterMode() {
    return false;
}

I am relatively new to Java so perhaps I'm missing something that is typical to Java source code here? 我是Java的新手,所以也许我在这里缺少Java源代码的典型特征? Is there other code that is be obfuscated from me? 还有其他令我困惑的代码吗?

First, the lack of a visibility modifier is often referred to as package-private . 首先,缺乏可见性修饰符通常被称为package-private It is in between protected and private on the visibility scale- only other classes within the same package can override package-private methods. 在可见性范围内,它介于protectedprivate之间,只有同一程序包中的其他类才能覆盖程序包私有方法。 See Controlling Access to members of a Class for more information. 有关更多信息,请参见控制对类成员的访问

The Android framework uses this often- it allows the framework to override those methods without allowing the end users (Android developers) to do the same and potentially interfere with how the framework operates. Android框架经常使用这种方法-它允许框架覆盖这些方法,而不允许最终用户(Android开发人员)执行相同的操作,并可能干扰框架的运行方式。

In this case, the default for AdapterView s is to not support filter mode at all. 在这种情况下, AdapterView的默认设置是根本不支持过滤器模式。

Some AdapterView subclasses do support it. 一些AdapterView子类确实支持它。 For example, AbsListView and it's descendants do. 例如, AbsListView及其后代。 In the case of AbsListView , this method returns the value of an internal property that tracks whether or not the list is actually in filter mode. 对于AbsListView ,此方法返回一个内部属性的值,该属性跟踪列表是否实际上处于过滤器模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM