Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some folks use Class#method instead of Class.method in correspondence?

When writing about methods in Java (i.e. in forums, mailing lists, issue trackers, etc.) many people separate the method name from the class name using the '#' symbol instead of Java's native . operator; for example, folks refer to Object#toString instead of Object.toString. Where does this syntax come from?

like image 884
Kevin Welker Avatar asked Jun 28 '12 15:06

Kevin Welker


People also ask

Why do we use class?

Why do we use? A Class is a construct that is used to create instances of itself. Members of a class can be fields and methods that enable an object of the class to maintain state and behavior respectively. ... Meaning, to have objects in object-oriented programing , you need to instantiate a class .

Why do we use class in OOPs?

Classes are required in OOPs because: It provides template for creating objects, which can bind code into data. It has definitions of methods and data. It supports inheritance property of Object Oriented Programming and hence can maintain class hierarchy.

What is the difference between a class and a function?

Functions do specific things, classes are specific things. Classes often have methods, which are functions that are associated with a particular class, and do things associated with the thing that the class is - but if all you want is to do something, a function is all you need.

How are classes and objects related to one another?

A class defines object properties including a valid range of values, and a default value. A class also describes object behavior. An object is a member or an "instance" of a class. An object has a state in which all of its properties have values that you either explicitly define or that are defined by default settings.


1 Answers

It's the notation used in javadoc comments when linking to another class' method.

EDIT

To gather the additional information provided in comments:

  • @Hugo notes that the # notation in turn comes from HTML anchors
  • @maksimov points out that Object.method is the Java syntax to call static methods, which could be misleading

UPDATE

Java 8 brings a new syntax for method references, which now seems to become more popular - so Object#toString tends to now be written Object::toString.

like image 102
assylias Avatar answered Oct 06 '22 08:10

assylias