Just in case if you are trying to apply an instance method from the same object where your code runs

Arrays.asList("a", "b", "c").forEach(this::print);
Answer from Sergey Shcherbakov on Stack Overflow
🌐
Coderanch
coderanch.com › t › 751439 › java › static-reference-static-method
Cannot make a static reference to the non-static method (Beginning Java forum at Coderanch)
May 3, 2022 - ... A static variable or method: there's only on per class no matter how many instances have been created. This includes zero instances. To access a static variable or method you use the class name, (dot), variable or method name. A non-static variable: there's one inside each instance of the class.
Discussions

java - Method reference for static and instance methods - Stack Overflow
You need objects of a particular type to access the non-static method. But, You do not need objects of a particular type to access the static method. String::toUpperCase works on instances of String. But you cannot access this method without having a String object to work on. Refer my comment ... More on stackoverflow.com
🌐 stackoverflow.com
java - Cannot make a static reference to the non-static method fxn(int) from the type Two - Stack Overflow
Possible Duplicate: What is the reason behind “non-static method cannot be referenced from a static context”? Cannot make a static reference to the non-static method cannot make a More on stackoverflow.com
🌐 stackoverflow.com
Calling Non-Static Method In Static Method In Java - Stack Overflow
I'm getting an error when I try to call a non-static method in a static class. Cannot make a static reference to the non-static method methodName() from the type playback I can't make the method ... More on stackoverflow.com
🌐 stackoverflow.com
Cannot make a static reference to a non-static method.
If you make your data member isCollected as static, your piece of code will work. But the important thing here that you should understand, is the use of the keyword 'static'. I think you should also read about Class variables and Instance variables. I hope this helps. More on reddit.com
🌐 r/javahelp
11
11
January 10, 2021
🌐
Reddit
reddit.com › r/javahelp › cannot make a static reference to a non-static method.
r/javahelp on Reddit: Cannot make a static reference to a non-static method.
January 10, 2021 -

This error is the most damning of all that i have encountered so far. I am a first year at uni and doing a coursework assessment to create a small game. We must use polymorphism, ArrayLists, animations etc. It's in Processing, which is basically Java.I am trying to modify a boolean from a unrelated class, to a different one.

ver.1

public Class Objects {

    public boolean isCollected = false;

}


Class Player {

    void collision() {
        if(x) {
            Objects.isCollected = true;
        }
    }
} 

ERROR: Cannot make a static reference to a non-static method.....

ver2.

public Class Objects {
public boolean isCollected = false;
    
    public void setIsCollected() {
        isCollected = true;
    }
}


Class Player {

    void collision() {
        if(x) {
            Objects.setIsCollected();
        }
    }
}

ERROR: Cannot make a static reference to a non-static method.....

Neither of the versions works, i tried adding an instance ofObjects object;

in the player class, but it only gives me a ERROR: NullPointerException - which i completely understand and knew it wouldn't work. Is it not possible to change the boolean isCollected without it being tied to a instance/object?

🌐
Oracle
docs.oracle.com › javase › tutorial › java › javaOO › methodreferences.html
Method References (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Similarly, the method reference String::concat would invoke the method a.concat(b). You can reference a constructor in the same way as a static method by using the name new.
🌐
InfoWorld
infoworld.com › home › blogs › java 101: learn java
Get started with method references in Java | InfoWorld
November 12, 2019 - I’m using the predefined Consumer functional interface, which meets the method reference/lambda requirements. The sort operation commences by passing the array to be sorted to Consumer‘s accept() method. Compile Listing 1 (javac MRDemo.java) and run the application (java MRDemo). You’ll observe the following output: ... A bound non-static method reference refers to a non-static method that’s bound to a receiver object.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-method-references
Java Method References - GeeksforGeeks
3 weeks ago - This type of method reference refers to an instance method of a specific object. The object is already created, and its method is referenced directly. Uses an existing object · Method must be non-static · Suitable for object-specific operations ...
Top answer
1 of 3
7

Why it is not allowing AppTest::makeUppercase?

The short answer is that AppTest::makeUppercase isn't valid "reference to an instance method of an arbitrary object of a particular type". AppTest::makeUppercase must implement interface Function<AppTest, String> to be valid reference.

Details:

There are 4 kinds of method references in Java:

  1. ContainingClass::staticMethodName - reference to a static method
  2. containingObject::instanceMethodName - reference to an instance method of a particular object
  3. ContainingType::methodName - reference to an instance method of an arbitrary object of a particular type
  4. ClassName::new - reference to a constructor

Every single kind of method reference requires corresponding Function interface implementation. You use as a parameter the reference to an instance method of an arbitrary object of a particular type. This kind of method reference has no explicit parameter variable in a method reference and requires implementation of the interface Function<ContainingType, String>. In other words, the type of the left operand has to be AppTest to make AppTest::makeUppercase compilable. String::toUpperCase works properly because the type of parameter and type of the instance are the same - String.

import static java.lang.System.out;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

class ReferenceSource {

    private String value;

    public ReferenceSource() {
    }

    public ReferenceSource(String value) {
        this.value = value;
    }

    public String doInstanceMethodOfParticularObject(final String value) {
        return ReferenceSource.toUpperCase(value);
    }

    public static String doStaticMethod(final String value) {
        return ReferenceSource.toUpperCase(value);
    }

    public String doInstanceMethodOfArbitraryObjectOfParticularType() {
        return ReferenceSource.toUpperCase(this.value);
    }

    private static String toUpperCase(final String value) {
        return Optional.ofNullable(value).map(String::toUpperCase).orElse("");
    }
}

public class Main {
    public static void main(String... args) {
        // #1 Ref. to a constructor
        final Supplier<ReferenceSource> refConstructor = ReferenceSource::new;
        final Function<String, ReferenceSource> refParameterizedConstructor = value -> new ReferenceSource(value);

        final ReferenceSource methodReferenceInstance = refConstructor.get();

        // #2 Ref. to an instance method of a particular object
        final UnaryOperator<String> refInstanceMethodOfParticularObject = methodReferenceInstance::doInstanceMethodOfParticularObject;

        // #3 Ref. to a static method
        final UnaryOperator<String> refStaticMethod = ReferenceSource::doStaticMethod;

        // #4 Ref. to an instance method of an arbitrary object of a particular type
        final Function<ReferenceSource, String> refInstanceMethodOfArbitraryObjectOfParticularType = ReferenceSource::doInstanceMethodOfArbitraryObjectOfParticularType;

        Arrays.stream(new String[] { "a", "b", "c" }).map(refInstanceMethodOfParticularObject).forEach(out::print);
        Arrays.stream(new String[] { "d", "e", "f" }).map(refStaticMethod).forEach(out::print);
        Arrays.stream(new String[] { "g", "h", "i" }).map(refParameterizedConstructor).map(refInstanceMethodOfArbitraryObjectOfParticularType)
                .forEach(out::print);
    }
}

Additionally, you could take a look at this and that thread.

2 of 3
1
String::toUpperCase

is short version of

text -> {
    return text.toUpperCase();
}

is again short version of

new Functon<String, String> (String text) {
    Override
    public String apply(String text) {
        return text.toUpperCase();
    }
}

so when you want AppTest::myMethod

you need

public class AppTest {

    public String myMethod(){
        return this.toString();
    }

    public void printFormattedString2(AppTest appTest, Function<AppTest, String> formatter){
        System.out.println(formatter.apply(appTest));
    }

    public static void main(String[] args) {
        AppTest appTest = new AppTest();

        appTest.printFormattedString2(appTest, AppTest::myMethod);
    }
}

because whole version looks so

appTest.printFormattedString2(appTest, new Function<AppTest, String>() {
    @Override
    public String apply(AppTest text) {
        return text.makeUppercase2();
    }
});
Find elsewhere
🌐
Javatpoint
javatpoint.com › java-8-method-reference
Java 8 Method Reference - javatpoint
Java 8 An Interface that contains exactly one abstract method is known as functional interface. It can have any number of default, static methods but can contain only one abstract method. It can also declare methods of object class.
🌐
W3Docs
w3docs.com › java
Cannot make a static reference to the non-static method
The "Cannot make a static reference to the non-static method" error occurs when you try to call a non-static method from a static context. In Java, non-static methods (also known as instance methods) belong to an instance of a class and can ...
🌐
Baeldung
baeldung.com › home › java › core java › method references in java
Method References in Java | Baeldung
March 26, 2025 - In this tutorial, we’ll explore method references in Java. We’ll begin with a very simple example, capitalizing and printing a list of Strings: List<String> messages = Arrays.asList("hello", "baeldung", "readers!"); We can achieve this by leveraging a simple lambda expression calling the StringUtils.capitalize() method directly: messages.forEach(word -> StringUtils.capitalize(word)); Or, we can use a method reference to simply refer to the capitalize static method:
🌐
Belief Driven Design
belief-driven-design.com › functional-programming-with-java-method-references-c9103cdf5f8
Functional Programming With Java: Method References | belief driven design
September 19, 2022 - It also allows you to refactor non-trivial or more complex lambdas to methods and use method references to streamline your code. Especially fluent pipelines, like Streams or Optionals, profit immensely from replacing and refactoring lambda expressions into method references. The general syntax for bound non-static method references is objectName::instanceMethodName
🌐
Baeldung
baeldung.com › home › java › core java › what is the error: “non-static method cannot be referenced from a static context”?
What Is the Error: “Non-static method cannot be referenced from a static context”? | Baeldung
July 6, 2024 - The compilation error “Non-static method … cannot be referenced from a static context” occurs when an attempt is made to call a non-static method from a static context.
🌐
InformIT
informit.com › articles › article.aspx
Method References | Java SE 8's New Language Features, Part 2: Predefined Functional Interfaces, Method References, and More | InformIT
A non-constructor method reference consists of a qualifier, followed by the :: symbol, followed by an identifier. The qualifier is either a type or an expression, and the identifier is the referenced method's name. The qualifier is a type for static methods, whereas the qualifier is a type ...
🌐
Rollbar
rollbar.com › home › how to resolve the non-static variable/method x cannot be referenced from a static context error in java
How to Resolve The Non-static Variable/Method X Cannot be Referenced from a Static Context Error in Java
February 19, 2025 - For the same reasons, a non-static method cannot be referenced from a static context, either, as the compiler cannot tell which particular object the non-static member belongs to.
🌐
Alvin Alexander
alvinalexander.com › blog › post › java › compiler-error-cannot-make-static-reference-to-non-static
Java error message: Cannot make a static reference to the non-static field or method | alvinalexander.com
July 27, 2018 - A short answer goes like this: In Java you have instance members (variables and methods) and static members: Instance members belong to an instance of a class (what we call an object) Static members can be accessed directly on the class (you don’t need an instance of a class to refer to static members)
🌐
Netjstech
netjstech.com › 2015 › 06 › static-reference-to-non-static-method-field-error.html
Fix Cannot make a static Reference to The Non-static Method Error | Tech Tutorials
The obvious solution to fix "Cannot make a static reference to the non-static method or a non-static field" error in Java is to create an instance of the class and then access the non-static members.
🌐
CodingNomads
codingnomads.com › how-to-call-static-nonstatic-methods-in-java
How to Call Static & Non-Static Methods in Java?
Inside a static method and calling a non-static method: create an object and use it as a reference.
🌐
javaspring
javaspring.net › blog › calling-non-static-method-in-static-method-in-java
How to Call a Non-Static Method from a Static Method in Java: Fixing 'Cannot Make Static Reference' Error — javaspring.net
Non-static methods, by contrast, depend on an instance of the class to access instance variables (like model in the Car example). Without an instance, Java can’t resolve which object’s data the method should use.