相关疑难解决方法(0)

用于组织项目的选项:JAX-RS API,ServiceLocator和远程EJB

我正在试图弄清楚我对API项目架构的选择.

我想使用JAX-RS 1.0版创建一个API.此API从更大,更旧,更复杂的应用程序中使用远程EJB(EJB 3.0).我正在使用Java 6.

到目前为止,我可以做到这一点并且有效.但我对解决方案不满意.看我的包裹配置.我的问题在代码后面描述:

/api/
    /com.organization.api.v1.rs -> Rest Services with the JAX-RS annotations
    /com.organization.api.v1.services -> Service classes used by Rest Services. Basically, they only have the logic to transform the DTOs objects from Remote EJBs in JSON. This is separated by API version, because the JSON can be different in each version.
    /com.organization.api.v1.vo -> View Objects returned by the Rest Services. They will be transformed in JSON using Gson.
    /com.organization.api.services -> Service classes used by versioned Services. 
        Here …
Run Code Online (Sandbox Code Playgroud)

java architecture jax-rs ejb-3.0 api-versioning

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


为什么接口方法不能"静态"和"最终"?

在Java Interface中,我们只能使用最终变量.我们还可以在Interface中创建静态变量.但是,与此同时,我们无法创建静态/最终方法,因为接口仅适用于静态方法.

在接口中不允许静态/最终方法的原因是什么?

java methods static final interface

7
推荐指数
3
解决办法
3万
查看次数

Android Studio:静态方法接口中的断点不起作用

Android Studio不会在接口的静态方法中停止.

示例:请参阅项目Conductor(version )的Utils.javagetFilteredNotes接口中的方法:0.9.3

public interface Utils {
    // some lines removed for readability

    static List<Note> getFilteredNotes(AppState appState) {
        List<Note> notes = appState.notes();
        NotesFilter filter = appState.filter();
        return filter(ConsPStack.from(notes), note ->
                filter == NotesFilter.ALL
                        || filter == NotesFilter.CHECKED && note.checked
                        || filter == NotesFilter.UNCHECKED && !note.checked);
    }
Run Code Online (Sandbox Code Playgroud)

当我将接口转换为类时,它工作:

public class Utils 
Run Code Online (Sandbox Code Playgroud)

为什么断点不能在界面上工作?

更多细节:

  • Android Studio版本 2.2.2
  • 虚拟设备: Nexus_6_API_25.avd
    • 安卓: 7.1.1
    • 中央处理器: x86
  • minifyEnabled=false调试版本的设置没有帮助
  • 该项目正在使用retrolambda

java android breakpoints android-studio retrolambda

6
推荐指数
0
解决办法
453
查看次数

为什么不能在本地类中声明成员接口?

您不能在像下面这样的块内声明接口

public void greetInEnglish() {

        interface HelloThere {
           public void greet();
        }

        class EnglishHelloThere implements HelloThere {
            public void greet() {
                System.out.println("Hello " + name);
            }
        }

        HelloThere myGreeting = new EnglishHelloThere();
        myGreeting.greet();
}
Run Code Online (Sandbox Code Playgroud)

本 Oracle 教程中,我得到了“您不能在本地类中声明成员接口”。因为“接口本质上是静态的”。

我渴望用更合理的信息来理解这一点,为什么界面本质上是静态的?

为什么上面的代码没有意义?

提前感谢您的介绍!

java oop interface class local

5
推荐指数
1
解决办法
792
查看次数

Eclipse不允许从另一个工作区访问外部jar中的静态接口方法

  • 有两种蚀工作区,工作区甲工作区乙.
  • Workspace A中,有一个项目,其中包含一个定义公共静态方法的接口:

    package workspacea;
    
    public interface Foo {
    
      public static String sayHello() {
        return "Hello, world!";
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 然后,我使用Export→Java→JAR文件和默认设置将整个项目从Workspace A导出到*.jar-File.

  • Workspace B中,类应该访问先前定义的静态方法:

    package workspaceb;
    
    import workspacea.Foo;
    
    public class Bar {
    
      public static void test() {
        String msg = Foo.sayHello();
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 使用项目属性→Java构建路径→库→添加外部JAR,将以前从Workspace A导出的*.jar 添加到Java构建路径中...

执行这些步骤后,该行Foo.sayHello(); 不会编译:

Unresolved compilation problem: 
This static method of interface Foo can only be accessed as Foo.sayHello
Run Code Online (Sandbox Code Playgroud)

根据我的理解,它应该编译(它可以Foo很好地识别界面).有趣的是,如果两个项目都位于同一个工作区 …

java eclipse jar

4
推荐指数
1
解决办法
2700
查看次数

静态方法继承在java中

假设我有一个POJO User,我添加了一些静态方法来执行CRUD操作:

public class User {
    private String name;
    private int age;

    // getter and setter omitted
    //
    public static void add(User user) {
        // add person
    }

    public static int delete(Object id) {
        // delete person
        return 1;
    }
}
Run Code Online (Sandbox Code Playgroud)

因为我有像User这样的其他实体,所以我想把这个adddelete方法抽象化,就像这样;

public class?interface Entity<T>{
    static add(T t);
    static delete(Object id);   
}

public class User extends Entity<User>{
    @override
    static add(User user){
        // add ...
    }

    ....
}
Run Code Online (Sandbox Code Playgroud)

这可能吗?

java inheritance overriding

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