java - 令人困惑的java : a method calls another method which returns something

标签 java android android-volley

我一直在研究这个tutorial下面的代码难倒了我:

public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}

public ImageLoader getImageLoader() {

    getRequestQueue();
    //getRequestQueue returns an object, but we dont have any variable to receive it.. how is this possible ?

    if (mImageLoader == null) {
        mImageLoader = new ImageLoader(this.mRequestQueue,
                new LruBitmapCache());
    }
    return this.mImageLoader;
}

所以问题是 getRequestQueue 返回一个对象,但我们没有任何变量来接收它..这怎么可能?

示例:不应该是这样的:

RequestQueue x = getRequestQueue();

因此,当我们没有将 RequestQueue 返回的内容捕获到变量中时,我们如何处理它?<​​/p>

最佳答案

getRequestQueue(),与它的名字相反,它实际上是一个有副作用的方法。这就是为什么调用该方法并丢弃其返回值是有意义的。方法返回后,程序的状态将发生变化。

关于java - 令人困惑的java : a method calls another method which returns something,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26298949/

相关文章:

android - Volley POST 参数不起作用?

android - 在 NetworkImageview Volley android 中加载不同的离线图像(默认图像)

java - 隐式引用是否应该优先于显式引用

android - android中的Binder运行时异常

android - Google AdMob 类型

android - 执行任务 : [clean,:app:assembleDebug] 错误 - Android Studio 3

android - Volley - 直接下载到文件(没有内存字节数组)

java - 检索项目 : No resource found that matches the given name android 的父级时出错

java - Maven依赖问题: Provided and Compile dependencies working together

java - 按子列表中的项目对 Java 列表进行排序