我正在试图弄清楚我对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 Interface中,我们只能使用最终变量.我们还可以在Interface中创建静态变量.但是,与此同时,我们无法创建静态/最终方法,因为接口仅适用于静态方法.
在接口中不允许静态/最终方法的原因是什么?
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)
为什么断点不能在界面上工作?
更多细节:
2.2.2Nexus_6_API_25.avd
7.1.1x86minifyEnabled=false调试版本的设置没有帮助您不能在像下面这样的块内声明接口
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 教程中,我得到了“您不能在本地类中声明成员接口”。因为“接口本质上是静态的”。
我渴望用更合理的信息来理解这一点,为什么界面本质上是静态的?
为什么上面的代码没有意义?
提前感谢您的介绍!
在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很好地识别界面).有趣的是,如果两个项目都位于同一个工作区 …
假设我有一个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这样的其他实体,所以我想把这个add和delete方法抽象化,就像这样;
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 ×7
interface ×2
oop ×2
android ×1
architecture ×1
breakpoints ×1
class ×1
eclipse ×1
ejb-3.0 ×1
final ×1
inheritance ×1
jar ×1
jax-rs ×1
local ×1
methods ×1
overriding ×1
retrolambda ×1
static ×1