gpt4 book ai didi

java - 如何解决: No source is available for type did you forget to inherit a required module?

转载 作者:行者123 更新时间:2023-11-30 04:51:45 26 4
gpt4 key购买 nike

shared包中,我有一个类,它只使用server包中的类,只有当它位于服务器上时,它才独立于GWT,并且我有使其短暂

if (!GWT.isClient())
ServerLogger loggerServer;

但它无法编译,因为它是共享的。我可以在这里工作吗?,我只是想让 GoogleCompile 工作,它不应该具有服务器记录器的功能。有解决办法吗?

如何编写我自己的模块,该模块总体为 NULL,因为我只想停止编译器的错误。

最佳答案

GWT 仍在尝试编译此代码。您将需要使用 Deferred Binding <super-source> 在编译时交换您需要的实现,以便 GWT 不会尝试编译此特定于服务器的代码。

要么就是,要么有ServerLogger实现是对此共享类的接口(interface)依赖,并在服务器/客户端中传递正确的实现:

// in your shared package

public class SharedClass {
private final LoggingClass logging;
public SharedClass(LoggingClass logging) {
this.logging = logging;
}

public void log(String msg) {
logging.log(msg);
}
}

public interface LoggingClass {
public void log(String msg);
}

// in your client package

public class ClientLogging implements LoggingClass {
public void log(String msg) { GWT.log(msg); }
}

// in your server package

public class ServerLogging implements LoggingClass {
public void log(String msg) { ServerLogger.log(msg); }
}

关于java - 如何解决: No source is available for type did you forget to inherit a required module?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com