在目标C中,两个不同的引用可能相互指向.
但这在Java中是否可行?我的意思是,两个对象引用可以互相指向吗?如果有可能,他们什么时候会被垃圾收集?
而且,在嵌套类的情况下,两个对象(内部类和外部类)相互链接 - 这些对象如何被垃圾收集?
我已经阅读并开始意识到实体(数据对象 - 用于JPA或序列化)注入其中是一个坏主意.这是我目前的设计(所有适当的字段都有getter和setter,serialVersionUID为简洁起见我放弃了).
这是父对象,它是实体组合图的头部.这是我序列化的对象.
public class State implements Serializable {
List<AbstractCar> cars = new ArrayList<>();
List<AbstractPlane> planes = new ArrayList<>();
// other objects similar to AbstractPlane as shown below
}
Run Code Online (Sandbox Code Playgroud)
AbstractPlane 它的子类只是没有注入的简单类:
public abstract class AbstractPlane implements Serializable {
long serialNumber;
}
public class PropellorPlane extends AbstractPlane {
int propellors;
}
public class EnginePlane extends AbstractPlane {
List<Engine> engines = new ArrayList<>(); // Engine is another pojo
}
// etc.
Run Code Online (Sandbox Code Playgroud)
相比之下,每种具体类型的汽车都需要一个拥有某些行为的经理以及一些特定形式的数据:
public abstract class AbstractCar implements Serializable { …Run Code Online (Sandbox Code Playgroud) 我在运行时配置中使用Wildfly 14和Java 11.当我启动服务器时,我得到了
org.jboss.modules.ModuleNotFoundException: java.se
at org.jboss.modules.Module.addPaths(Module.java:1266)
at org.jboss.modules.Module.link(Module.java:1622)
at org.jboss.modules.Module.relinkIfNecessary(Module.java:1650)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:296)
at org.jboss.modules.Main.main(Main.java:437)
Run Code Online (Sandbox Code Playgroud)
如何使用java 11运行Wildfly 14?
我有一个数组列表,我迭代.在每次迭代中,我调用get()以获取一个元素,如果该项目通过某些条件,则使用它将其添加到新的数组列表中add()
List<Item> items = new ArrayList<Item>();
List<Item> lessItems = new ArrayList<Item>();
for(int index = 0; index < items.size(); index++){
Item toCheck = items.get(i);
if(toCheck meets some condition){
lessItems.add(toCheck);
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定这里的时间复杂程度.我在所有项目上调用get(),这样就是O(n).然后我也在潜在的所有项目上调用add(),所以还有另一个O(n).这个不太确定.
我想在3D形状上创造"神光"效果/照明.如果我有一个Box,我想在它背后有一个光源,它会在它周围产生"神光".下面是我发现的一个图像,显示了这个想法(想象一下窗口是一个不透明的盒子,四周都是光线):
我尝试设置一个PointLight光源,但所有灯光都会照亮"实心"物体,因此您无法看到它们周围的效果.我的猜测是填充形状周围的区域,用某种类似空气的,部分透明的材料填充形状; 并且光可以从中反射出来.
我将如何创造"神光?
我按照http://docs.gluonhq.com/charm/4.0.1/#_getting_started上的说明进行操作.我正在使用eclipse 4.5.2和JDK 1.8.0_102.我还从https://developer.android.com/studio/index.html#Other下载了带有24/25 API级别SDK的Android Studio .这是我做的:
gradle -v返回正确的信息.打开"显示视图"菜单
和选定的Gradle任务
gradle任务视图与教程不同:
我选择了GluonTest/application/run任务,它在桌面上运行良好.但是我无法找到你在图片中看到的任务androidInstall和launchIOSDevice任务.
这是我的gradle.build文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.1.1'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'gluon.main.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.0.1'
}
jfxmobile {
downConfig {
version = '3.0.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
} …Run Code Online (Sandbox Code Playgroud) 我像这样声明一个bean,
<bean id="booleabBeab" class="java.lang.Boolean" init-method="booleanValue()"></bean>
Run Code Online (Sandbox Code Playgroud)
但我在
ApplicationContext spring = new ClassPathXmlApplicationContext(configFileName);
Run Code Online (Sandbox Code Playgroud)
错误是:
无法实例化 [java.lang.Boolean]:未找到默认构造函数;嵌套异常是
java.lang.NoSuchMethodException:java.lang.Boolean.<init>()
这个让我很困惑.我创建了一个基于在Wildfly 10.1上运行的JavaEE7的最小JAX-RS应用程序.
@ApplicationPath("")
public class JAXRSConfiguration extends Application {
@Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(Resource.class));
}
}
Run Code Online (Sandbox Code Playgroud)
资源注入一个虚拟无状态bean:
@Path("")
public class Resource {
@Inject
Manager manager;
@GET
@Path("/go")
public void go() {
manager.call();
}
}
Run Code Online (Sandbox Code Playgroud)
这是豆子:
@Stateless
public class Manager {
@PostConstruct
private void init() {
System.out.println("POST CONSTRUCT ");
}
void call() {
System.out.println("called ");
}
}
Run Code Online (Sandbox Code Playgroud)
使用浏览器执行GET会导致以下错误:
org.jboss.resteasy.spi.UnhandledException: org.jboss.weld.exceptions.WeldException: Class org.jboss.weld.util.reflection.Reflections can not access a member of class com.a.b.Manager with modifiers ""
Run Code Online (Sandbox Code Playgroud)
可以发布完整堆栈跟踪,但所有引发的消息都是相同的.
我搜索了这个错误,它发生在注入的bean 不公开的时候,但我的是.我决定试图移除公众,看看它会抱怨什么,并且...它的工作原理.注入bean,注入任何可能注入的注入,调用post构造方法并打印所有打印件.
这与 …
我有这些课程:
class Parent {
BooleanProperty total = new SimpleBooleanProperty();
SimpleListProperty<Child> children = new SimpleListProperty<>(FXCollections.observableArrayList());
}
class Child {
BooleanProperty single = new SimpleBooleanProperty();
}
Run Code Online (Sandbox Code Playgroud)
我想要的是,total当且仅当所有孩子single都是假的时候,这将是假的.换句话说,当且仅当有一个孩子single为真时,total才是真的.
我想出了这个绑定
total.bind(Bindings.createBooleanBinding(() -> {
return children.stream().filter(c -> c.isSingle()).findAny().isPresent();
}, children.stream().map(c -> c.single).collect(Collectors.toCollection(FXCollections::observableArrayList))));
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗?
我也应该total只读,因为写入绑定属性会抛出异常吗?
我有一个客户端和一个服务器,两者都是用 Java 编写的,并且共享应该在彼此之间发送的 Java 类。我不确定我可以在移动设备上使用哪些库,因为我不知道 Dalvik 支持什么、RoboVM 支持什么等。不知道在这种情况下 Gluon Mobile 可以为我做什么。
具体来说,我有一个如下所示的文件:
class Data {
IntegerProperty int1 = new SimpleIntegerProperty(4);
ObjectProperty<Person> person = new SimpleObjectProperty();
ObservableList<Contact> contacts = FXCollections.observableArrayList();
// other properties
// also add the getters for the properties and the getters and setters for the values
}
Run Code Online (Sandbox Code Playgroud)
Person与Contact上面类似 - 它们主要包含数据属性和一些用于添加和从内部(私有)列表中删除的方法等。基本上它们就像只是带有属性包装器的bean或POJO。这是需要在服务器和客户端之间发送的数据,但只有包装的值很重要,而不是绑定。这让我想到了关于序列化的问题:javaFX 属性不可序列化,因此在这里建议将上述类制作为可外部化的类,并写入和读取包装的值。
最终,我不在乎我是否需要做这些定制的事情(尽管这是很多工作)或者是否有解决方法。我需要在服务器上有一个客户端可以调用的方法Data receiveDatafor(...),服务器获取Data data并返回它。客户端和服务器各自具有与Data对象无关的绑定。
目前我们在桌面内部使用 RMI。我读到 RMI 不受支持,而且它可能不是一个很好的选择,但它确实允许非常轻松地发送 java 对象。JavaEE 有 websockets,可以传输对象的二进制形式,但它是 …
类似于如何在 javafx 中获取 3D 对象窗口上的 2D 坐标,但我无法使解决方案起作用。
我想为 3D 形状绘制 2D 边框或更类似于其投影。我写了这个示例代码供参考:
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class CoordinateConversion extends Application {
@Override
public void start(Stage stage) {
var box = new Box(20, 20, 20);
box.setMaterial(new PhongMaterial(Color.TEAL));
box.getTransforms().add(new Rotate(45, new Point3D(1, 1, 1)));
var …Run Code Online (Sandbox Code Playgroud) 我已经在网站上查看了与该错误有关的其他问题,但其中大多数都是关于SessionScope的,或者没有答案。唯一可能有用的是从线程中调用bean时,作用域类型javax.enterprise.context.RequestScoped没有活动上下文,但它不在我所拥有的上下文中。
我在Wildfly 10.1(Java ee 7)上运行JAX-RS端点。看起来像这样:
@Path("")
public class ServerResource {
@Inject
Order order;
@Resource
ManagedExecutorService mes;
@PUT
@Path("/prepareOrder")
public void prepareOrder(@Suspended AsyncResponse response) {
mes.execute(() -> {
try {
Item item = new Item(); // JPA entity
order.setItem(item); // line 71
// call a service to save the order data (like item) to the DB
} catch (Exception e) {
e.printStackTrace();
response.resume(false);
}
response.resume(true);
});
}
}
Run Code Online (Sandbox Code Playgroud)
我添加try-catch仅仅是因为这个问题,它通常不存在。 Order是
@Stateful
@RequestScoped
public class Order {
private Item …Run Code Online (Sandbox Code Playgroud) 我想通过运行Wildfly的2个独立实例来模拟2台服务器.当您不希望在同一实例上部署所有WAR,然后只能将它们关闭并一起启动时,这非常有用.
我正在使用带有JBoss插件的Eclipse,在Servers视图中我想拥有2台Wildfly服务器,我可以单独和同时停止和运行.我怎么做?