Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone
I've creating this code in the Layer class:
Java
public class Network {
List<Layer> layers = new ArrayList();
public List<Layer> getLayers() {
		return this.layers;
	}
}


I've used this in the main method:
Java
List<Layer> layers = new ArrayList();
layers = NeuralNetwork.getLayers();
		for(Layer layer : layers) {
			System.out.println(layer);
		}


My output:
VB
Layers.Layer@15db9742
Layers.Layer@6d06d69c
Layers.Layer@7852e922


Question:
I want to print the output as inputLayer, hiddenLayer and outputLayer(object names of the layer class) and not it's heap values.How could I do it?
My Approach was:
-to create a new field called private String layerName and pass it into the layer's constructor and then create a getter(public String getLayerName()) to get the name of the appropriate layer.

Any better approach?

Thank you
Posted

1 solution

The 'correct' approach, is to store the name somwwhere in the object. You then add your own implementation of toString which returns the name as a string. If you do not want to store the name, then you can use reflection to obtain it from the class details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900