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.
Related
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?
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().
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 1 year ago.
Improve this question
Is there a way in java that interface can deliver function with already implemented part of code? e.g.
//somewhere in java classes
void function1(){
MyClient client = MyClient.getNew();
if(client.isReal()){
// function2 is an expansion for function1
}
}
//someInterface.java
public interface someInterface{
public void function2(MyClient client);
}
//someClass.java
public class someClass implements someInterface{
#Override
public void function2(MyClient client){
client.send("Hi!");
}
}
Maybe I didn't make it clear. I want to make an interface that delivers a function. No problem. But this function must implement some logic checks. How can I do that?
Yes, you can. You have to write a default method in your interface. Please go through this tutorial to find more details.
Java 8 has introduced the notion of "default methods", so you can definitively implement a method on an interface.
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");
}
});
}
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.