Don’t assign static references to instance method calls in Java

Photo by Luca Bravo on Unsplash

Assigning a static reference to an instance method call could be perilous. Let’s take a look at an example Java class to examine why:

/**
* Foo.java
*/

public class Foo {
public static String foo = Config.getInstance().getFoo();
}

Seems pretty innocuous in itself, but ostensibly we’re just assigning static reference in Foo

--

--

--

Software Engineer. 70% of my body is made of code.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

7 Things I Want Any New Engineer On My Team To Know

Building a Scalable Caching Platform

CI CD Pipeline: Learn How to Setup a CI CD Pipeline From Scratch

Writing clean code in a legacy codebase

How to Get Continuous Integration Right

Docker Container Networking. C++ client — server app.

Building nearline system for scale and performance: Part 1

How to deploy your AI model on Edge devices with Azure

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Patrick Brown

Patrick Brown

Software Engineer. 70% of my body is made of code.

More from Medium

Can I modify an object by a Java method call?

Return nothing, with Java Optionals

Evaluation of binary expression tree

Top tech company coding challenge

Functional Interface in Java | Rajeev Sarraf