Java Efficiency – Wrapping Simple Statement in a Function

efficiencyfunctionsjava

I was working on neo4j graph database in java. To get the reference node of this db:

    GraphDatabaseService graphDb=new EmbeddedGraphDatabase(DB_PATH);

    Node Root=graphDb.getReferenceNode()

I always forget to prefix graphDb when calling getReferenceNode(). So what I did :

   public Node getRootNode(){
   return graphDb.getReferenceNode(); }

Now after doing this , I thought this to be overkill as I am replacing a simple statement with a function call which surely has overhead but using getRootNode seems more intuitive to me.

So my question is am I right in thinking that doing the above mentioned thing is inefficient? Or does it not affect performance that much?

Best Answer

You can also just store the referenceNode in a variable as it is constant per GraphDatabaseService.

You can also declare it as a final instance variable in the constructor of your service to document that.