java

Syntax error: insert “enum Identifier”, insert “EnumBody”, inset “}”

▼魔方 西西 提交于 2021-02-18 11:57:05
问题 I coded an enum type which brings up the following Syntax errors when I run my created JUnit test for it: java.lang.Error: Unresolved compilation problems: Syntax error, insert "enum Identifier" to complete EnumHeaderName Syntax error, insert "EnumBody" to complete EnumDeclaration Syntax error, insert "}" to complete ClassBody My enum type has static functions which for a particular String, returns an enum constant. Here is some of my code of the enum type: public enum MusicType { ACCIDENTAL,

Java - Create new Instance using Reflection without knowing constructor params

◇◆丶佛笑我妖孽 提交于 2021-02-18 11:56:07
问题 I need to create new instances of many classes. I'm using reflection but when I make c.newInstance(), the classes without 'empty parameter constructor' throws an java.lang.InstantiationException. Now, how can i do to create instances of every classes ? I know that i can use c.getConstructor(Class).newinstance(params) to create instances of classes that doesn't have 'empty parameter constructor', but i do not know the params of each classes. One more thing, all those classes extend from

Test lambda expressions called by dependencies

夙愿已清 提交于 2021-02-18 11:47:31
问题 I am trying to test some code inside lambda expression which is a call back from another class. class EmailSender { private EmailBuilder emailBuilder; public void send() { String testEmail = emailBuilder.buildEmail("Test Email", bodyContentAppender()); //send testEmail } private Consumer<Email> bodyContentAppender() { //how to test this through JUnit? return email -> email.appendBody("Body Content"); } } interface EmailBuilder { String buildEmail(String templateName, Consumer<Email>

how to select one cell from SWT table

好久不见. 提交于 2021-02-18 11:47:09
问题 table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if(table.getSelectionIndex() != -1) { System.out.println(table.getSelectionIndex()); TableItem item = table.getItem(table.getSelectionIndex()); System.out.println(item.toString()); } else {} } }); when i click on any cell in my table, only the first cell of that row is selected and returned and not exactly that cell please tell me how can i select and get item from exactly that cell which i

How to disable AspectJ dump files “ajcore.txt”

北城余情 提交于 2021-02-18 11:45:10
问题 I've got a Tomcat webapp where I'm using AspectJ for logging and metrics, everything seems fine, but it keep creating several files like ajcore.20150310.113255.780.txt in the root folder. There is no exception in this files, so they are completely useless. I've found this: https://eclipse.org/aspectj/doc/released/pdguide/ajcore.html That states that using org.aspectj.weaver.Dump.exception="false" should disable this behavior, yet the files are still appearing. Is there any other way to

Specifying multiple conditions in xpath

旧时模样 提交于 2021-02-18 11:42:05
问题 I want to select all the tags with <td class='blob-code blob-code-addition'> and <td class='blob-code blob-code-deletion'> . So I am trying to include or condition here between the two predicates. It does not work. However, if I include only one of the two classes it works . What is the problem here? Something is wrong with the syntax. By getChanges = By.xpath("//td[@class='blob-code blob-code-addition'] or //td[@class='blob-code blob-code-deletion']"); 回答1: You want to specify that like the

Make a “Fake” mouse in java?

一世执手 提交于 2021-02-18 11:41:16
问题 In java you can use the Robot Class to move the mouse and fire mouse clicks. While this is cool, it also "hijacks" the users mouse, so you cannot multitask. What I want to do is make a "Fake" mouse that acts independently of the system's mouse cursor, and lives only inside my java applet. In this sense the applet would think it was being clicked by the mouse in various (x,y) positions (within the applet), however I can do whatever I want with the system mouse and it will not be affected. I

How should javac 11 link methods overridden in later versions with a Java 8 target?

被刻印的时光 ゝ 提交于 2021-02-18 11:36:33
问题 Let's say I'm using Java 11 javac, but I'm using the --source and --target options set to 1.8 so that my source code will be considered Java 8 and the output .class files will be compatible with Java 8. My goal is to produce .class files that can run on a Java 8 JVM. And let's say I have the following Java 8 code I'm compiling: import java.nio.ByteBuffer; … ByteBuffer byteBuffer = …; //init somehow byteBuffer.flip(); //what ends up in the `.class` file? The question is: what should Java 11

How does spring achieve dependency injection at runtime?

百般思念 提交于 2021-02-18 11:36:30
问题 Does anyone know what technique spring uses to achieve dependency injection at runtime? Does it simply use aspects (AOP) or is it something more complicated? 回答1: Spring does a lot of things, but dependency injection itself is actually a surprisingly simple mechanism. It starts with having a registry for classes that are available for injection. Classes that are added to this registry are examined using reflection. A DI framework will look for relevant annotations and constructors to

How does spring achieve dependency injection at runtime?

百般思念 提交于 2021-02-18 11:36:03
问题 Does anyone know what technique spring uses to achieve dependency injection at runtime? Does it simply use aspects (AOP) or is it something more complicated? 回答1: Spring does a lot of things, but dependency injection itself is actually a surprisingly simple mechanism. It starts with having a registry for classes that are available for injection. Classes that are added to this registry are examined using reflection. A DI framework will look for relevant annotations and constructors to