I’m learning Java and find myself sending methods around while asking for help but my problem is I have many methods and the data is modified at each method. I often have to send large files when only one area is relevant(it makes my SO questions excessively long as well).
But for some of the stuff I do, I can’t get the right data format to be outputted as string that I can input later. For example, if I add data to a list of Points(like this, (new Point(0, 0));) then when I output the results I get something like this(with sample data):
[java.awt.Point[x=970,y=10], java.awt.Point[x=65,y=10], java.awt.Point[x=729,y=10]
I get errors when I assign this to a variable and send it to my method I want to test/show. I basically have two goals:
- If I want help on a single method(thats part of a much larger class), I want to be able to send the least amount of code to the person helping me(ideally just the method itself and the inputs..which I’m unable to capture exactly right now).
- When I test my code, I would like a way to isolate a method so I don’t have to run a large file when all I can about is improving one method.
I am pretty sure I’m not the first person to come across this problem, How can I approach this?
UPDATE: Here’s an example,
double[] data = new double[] {.05, .02, -.03, .04, .01};
System.out.println(data); //output is: [D@13fcf0ce
If I make a new variable of this and send it to a method I get errors. I have 30 methods in a class. I want to have a friend help me with one. I’m to avoid sending 29 methods that are irrelevant to the person. So I need a way to capture the data, but printout doesn’t seem to capture it in a way I can send to methods.
Java outputs variables in a way that is human-readable (although it depends on the object’s
toStringmethod). The output oftoStringis (unsurprisingly) aString. Unless you have a parsing mechanism to turn a string back into the original object, it’s a one-way operation.There should be no need to turn it back into the original object, however. If you’re trying to isolate a function and sample data, the easiest thing to do is encapsulate it in a test and some data–there are many different ways to do this and communicate it to someone else.
I’m still unclear on your usecase, however. If it’s an SO question, all you should need to do is show the code in question, provide a minimal amount of data that shows the problem, and you’re done. This could be done in a self-contained example where you simple create the data in code, as a unit test, or by showing the string output as you’ve already done.
If you’re trying to communicate the issue to a tech support tier, then the best mechanism depends entirely on what they’re equipped to handle–they’ll tell you if you didn’t do it right, believe me.