小编sam*_*sam的帖子

Java Reflection从一个字段中获取实例

有没有办法从一个领域获得实例?
这是一个示例代码:

public class Apple {
    // ... a bunch of stuffs..
}

public class Person {
    @MyAnnotation(value=123)
    private Apple apple;
}

public class AppleList {
    public add(Apple apple) {
        //...
    }
}

public class Main {
    public static void main(String args[]) {
        Person person = new Person();
        Field field = person.getClass().getDeclaredField("apple");

        // Do some random stuffs with the annotation ...

        AppleList appleList = new AppleList();

        // Now I want to add the "apple" instance into appleList, which I think …
Run Code Online (Sandbox Code Playgroud)

java reflection field instance

8
推荐指数
1
解决办法
1万
查看次数

Restangular - 如何覆盖错误拦截器

我正在使用AngularJS v1.2.16Restangular v1.4.0,并想知道是否可以覆盖ErrorInterceptor.如果有,怎么样?如果不是,我该如何解决?

我已经配置了一个错误拦截器,如下所示:

RestangularProvider.setErrorInterceptor(
    function ( response ) {
        if ( response.status == 401 ) {
        dialogs.error("Unauthorized - Error 401", "You must be authenticated in order to access this content.")
            .result.then( function () {
                $location.path("/login");
            });
        }
        else {
            // Some other unknown Error.
            console.log( response );
            dialogs.error(response.statusText + " - Error " + response.status,
                "An unknown error has occurred.<br>Details: " + response.data);
        }
        // Stop the promise chain.
        return false;
    }
);
Run Code Online (Sandbox Code Playgroud)

然后,在另一个地方,我进行了一个错误处理的POST调用.

function …
Run Code Online (Sandbox Code Playgroud)

angularjs restangular

7
推荐指数
1
解决办法
8091
查看次数

标签 统计

angularjs ×1

field ×1

instance ×1

java ×1

reflection ×1

restangular ×1