I would like to create a method, which will, besides other things, create an object named like the method argument. (I apologize if it is solved somewhere else, didn't find it) Something like as follows:
public return_type method (String ARGUMENT1)
{
...
ClassOfSomeKind objectOfSomeKind someprefix_ARGUMENT1 = new ClassOfSomeKind();
}
That's naming a variable - not an object. Objects don't have names, as such. (You can have a field called name
of course, but it's not a general thing.)
Variable names are usually only relevant at compile time - so it doesn't really make sense to do this dynamically.
It sounds like you probably want a Map<String, YourClassType>
so that you can associate each object with a name and then fetch it later. So something like:
class Foo {
private final Map<String, Bar> bars = new HashMap<>();
public Bar createBar(String name) {
Bar bar = new Bar();
bars.put(name, bar);
return bar;
}
public void processBar(String name) {
Bar bar = bars.get(name);
if (bar == null) {
// No Bar for that name...
// Maybe throw an exception?
}
// Do something with bar
}
}
See more on this question at Stackoverflow