Java/Processing is that possible ? void hello(void funktion) [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hey guys i got a fast question, is that possible in Java or Processing ?
void hello(void bye)
{
//
}

With Java 8 you can use a lambda.
With Processing, you can use an anonymous class that implements a functional interface. Something like this:
interface DoFunction{
void do();
}
void hello(DoFunction function){
function.do();
}
void setup(){
hello(new DoFunction(){
void do(){
println("here");
}
});
}

Related

java composition to reduce code complexity [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 days ago.
Improve this question
Let us say there is a class LargeClass with 4k lines of code. I would like to reduce the file size to manage it better by extracting the code into some other classes.
class LargeClass extends SomeLibraryClass {
void featureOneLargeMethod1() {
}
void featureOneLargeMethod2() {
}
void featureOneLargeMethod3() {
}
void featureTwoLargeMethod1() {
}
void featureTwoLargeMethod2() {
}
void featureTwoLargeMethod3() {
}
}
I could create two classes FeatureOne and FeatureTwo and move the corresponding methods into these new classes but the featureOneLargeMethod1() calls protected SomeLibraryClass.someLibraryMethod() which makes it impossible to move these methods. I was thinking of creating a wrapper interface that LargeClass implements and thereby FeatureOne and FeatureTwo class can access them. Any better approach in java or kotlin instead of creating the wrapper interface?

Which functional interface to use if method don't accept anything but return object of the class in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I have one existing Java 7 method which accepts nothing but return class instance. I want to change it in java 8 using any existing functional interface but don't know what i can use here.
public NotificationPage infraSelection() {
......
return this;
}
Here NotificationPage is class name.
Maybe you can use the Supplier<T> interface?
It declares the method T get().

How to make method which is in other method? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
public void drawEverything(Canvas canvas) {
....
}
I want to make a method that can use canvas.
Question 1. Can I make a method in drawEverything()?
Question 2. How can I solve this?
I solved it!!!!
pubilc class outterClass {
public void drawMacro(Canvas canvas, .....) {
}
public void drawEveryThing(Canvas canvas) {
....
drawMacro(canvas, ....);
...
}
}
Thank you for your advice!!
I am not sure what you mean exactly.
If you want to use canvas in drawMacro it is impossible because canvas is just a parameter.
If you can describe your question in detail, I may give your better advice.
May it helps, best regard.

Declaring a constant in java [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have come across something rather strange today. A java developer has declared a constant like this:
public final class Constants {
public static final String KEY_COLUMN = AbstractDataRow.standardiseColumnName("key");
... // rest of implementation
}
public abstract class AbstractDataRow implements IRow {
public static String standardiseColumnName(String columnName) {
return columnName.trim().toLowerCase();
... // rest of implementation
}
}
What is strange to me is that KEY_COLUMN calls a method from an abstract class.
Is this good practice?
answering your question.. Not really.
You could just as easy call that string into the method already defined.. then convert that string to lowercase.
send the string to the method instead of the method to the string.

Is there a way to change ActionListeners from public void to something else? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to run a public static int when a JButton is pressed, but I cant run it from the public void. Is there any way I can get around that?
btnGoMining.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent arg0) {
Mining(randomOre, oresGet, mineTime, Inventory);
}
});
No. The interface defines the method signature, so the only thing you can do is add final or synchronized to it since they're not considered to be part of the method signature.

Categories

Resources