Abstract Factory Design: Replacing if else with enum

When we use Abstract Factory Pattern , we generally have FactoryMaker class which has a getFactory function in which we pass argument and we have switch or if-else logic in the function on the passed parameter to decide which factory to return. Is creating passed parameter an enum or an object and then having the logic of which factory to return inside those object will be better. For example :

抽象工厂设计:用枚举代替

当我们使用Abstract Factory Pattern ,我们一般有FactoryMaker其中有一类getFactory中,我们通过参数的功能,我们有switch或if-else上传递的参数的功能逻辑来决定要返回的工厂。 创建一个枚举或一个对象的传递参数,然后让这些对象内的哪个工厂返回的逻辑会更好。 例如 : 让我们说我们这个工厂制造商,它通过enum CountryCode来决定工厂。 public class FacoryMaker { public final static FacoryMaker fct

Java Abstract class Unusual behavior

Abstract Class: public abstract class ParentClass { private static ParentClass mpParentClass; public ParentClass() { mpParentClass = this; } public abstract void method1(); public static ParentClass getInstance() { return mpParentClass; } } Child Class : public class ChildClass extends ParentClass{ @Override public void method1() {

Java抽象类不寻常的行为

抽象类: public abstract class ParentClass { private static ParentClass mpParentClass; public ParentClass() { mpParentClass = this; } public abstract void method1(); public static ParentClass getInstance() { return mpParentClass; } } 儿童班: public class ChildClass extends ParentClass{ @Override public void method1() { System.out.p

Java Decompiler generates abstract enum

I used JD to decompile a .jar executable file. I encountered an abstract enum code which does not compile: private static abstract enum Type { ANONYMOUS(4) , STANDARD(0); private final int start; private Type(int start) { this.start = start; } public int getStart() { return this.start; } public abstract void insertHeader(Sheet paramSheet,

Java Decompiler生成抽象枚举

我用JD来反编译一个.jar可执行文件。 我遇到了一个不能编译的抽象枚举代码: private static abstract enum Type { ANONYMOUS(4) , STANDARD(0); private final int start; private Type(int start) { this.start = start; } public int getStart() { return this.start; } public abstract void insertHeader(Sheet paramSheet, SummaryCodec.Style paramStyle,

Compile all files in src?

Here's what I've got: /myjava/compile.cmd /myjava/src/a/HelloWorld.java /myjava/src/b/Inner.java /myjava/src/b/Inner2.java /myjava/bin HelloWorld: package a_pack; import b_pack.Inner; import b_back.Inner2; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); Inner myInner = new Inner(); myInner.

编译src中的所有文件?

这是我得到的: /myjava/compile.cmd /myjava/src/a/HelloWorld.java /myjava/src/b/Inner.java /myjava/src/b/Inner2.java /myjava/bin 你好,世界: package a_pack; import b_pack.Inner; import b_back.Inner2; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); Inner myInner = new Inner(); myInner.myInner();

Is it possible to write a plain old java program that runs on android?

I see tutorials that show you how to make a real android application with activities and all that, but all I really want to do is make a java class that has a public void static main(String params[]) { System.out.println("Hello World");} and run it with java HelloWorld on an android machine. Is that possible? There's a great app on the Android market called Terminal IDE that incl

是否有可能编写一个在android上运行的普通旧java程序?

我看到教程,告诉你如何使用活动和所有这些来制作一个真正的android应用程序,但是我真正想做的是创建一个具有public static static main的java类(String params []){System.out.println (“Hello World”);}并在Android机器上使用java HelloWorld运行它。 那可能吗? 在Android市场上有一个名为Terminal IDE的优秀应用程序,其中包括一个优秀的shell环境,vim / nano和java / javac,它们都编译为可在Android上本机运行。

Vert.x: correctly stream to http response in case of closed client connection

I have the following usecase for a vert.x aplication: write a REST handler for a GET request in this handler copy data from a ReadStream onto the response This looked straight forward, in the handler I would create the ReadStream and then use a Pump to pipe the stream onto the response (WriteStream). I noticed however that it can happen that the client closes the HTTP connection to my han

在关闭客户端连接的情况下,Vert.x:正确地流到http响应

我有以下用于vert.x应用程序的用例: 为GET请求编写一个REST处理程序 在这个处理程序中将数据从ReadStream复制到响应中 这看起来很简单,在处理程序中,我将创建ReadStream,然后使用Pump将流传输到响应(WriteStream)上。 然而,我注意到,在泵仍处于活动状态时,客户端可能会关闭与我的处理程序的HTTP连接。 在这种情况下,我期待WriteStream实例发生异常。 但事实并非如此,WriteStream#writeQueueFull方法返回“t

Anonymous Inner classes and Final modifier

To my understand correctly anonymous classes are always final : This has been mentioned specifically in JLS 15.9.5 However, when i run the following code to check that it is showing that Inner class is not final . public class Test{ static class A<T> { } public static void main(String arg[]) { A<Integer> obj = new A() { }; if ((obj.getClass

匿名内部类和最终修饰符

为了我的理解,正确的anonymous classes永远是final : 这已在JLS 15.9.5中具体提及 但是,当我运行下面的代码来检查它是否显示Inner类不是final 。 public class Test{ static class A<T> { } public static void main(String arg[]) { A<Integer> obj = new A() { }; if ((obj.getClass().getModifiers() & Modifier.FINAL) != 0) { System.out.prin

buddy: generate classes with cyclic types

I'm trying to generate classes with a cyclic class dependency, similar to this question: Byte Buddy - Handling cyclic references in generated classes As a minimal example, the kind of classes I want to generate have dependencies like this: //class A depends on class B, and vice-versa final class A { B theB; } final class B { A theA; } The accepted answer in the link above did not provide

好友:使用循环类型生成类

我试图用循环类依赖关系生成类,类似于这个问题:Byte Buddy - 处理生成类中的循环引用 作为一个最简单的例子,我想要生成的类有这样的依赖关系: //class A depends on class B, and vice-versa final class A { B theB; } final class B { A theA; } 上面链接中接受的答案并没有为我提供足够的信息来使其发挥作用。 这是我试过的: import net.bytebuddy.ByteBuddy; import net.bytebuddy.description.type.TypeDescript

IntelliJ Idea doesn't recognize Lombok's annotations

This question already has an answer here: Can't compile project when I'm using Lombok under IntelliJ IDEA 19 answers What helped was going into File | Project structure and adding a library from Maven (via search for org.projectlombok there): That downloaded the missing jar into the local repo which I assumed should have been done by the Lombok plugin. Seems to be yet another Int

IntelliJ Idea不承认Lombok的注释

这个问题在这里已经有了答案: 在IntelliJ IDEA 19答案下使用Lombok时无法编译项目 什么帮助进入了File | 项目结构并从Maven添加一个库(通过在那里搜索org.projectlombok): 那个下载缺失的jar到我认为应该由Lombok插件完成的本地回购。 似乎是另一个IntelliJ Idea错误,或者至少是在Lombok和IntelliJ插件文档中都没有明确提及的一个缺点。 我在这里提出了一个问题,也许这会在此期间为其他开发人员节省一些费用。

How to make lombok annotation @NotNull work in IntelliJ?

For some reason lombok @NotNull annotation does not work in my maven project in IntelliJ IDEA. I have a maven lombok dependency on version 1.16.16. Here is my import statements. As you see other lombok dependencies work fine. I discovered that @NotNull annotation has retention policy CLASS and other annotations (@Data, @NoArgsConstructor, etc) have retention policy SOURCE. Any ideas how t

如何使lombok注释@NotNull在IntelliJ中工作?

出于某种原因,lombok @NotNull注释在我的IntelliJ IDEA的Maven项目中不起作用。 我有一个maven lombok依赖版本1.16.16。 这是我的进口报表。 正如你看到其他lombok依赖项正常工作。 我发现@NotNull注释具有保留策略CLASS和其他注释(@Data,@NoArgsConstructor等)具有保留策略的源。 任何想法如何解决这个问题? 注释是@NonNull,带有'n'