1

I wanted to look at the source for the getRowVector method of the RealMatrix class in the Apache Commons Math library. I found it here: grepcode.

For some reason though, seemingly none of the methods shown have any implementation; they all look like function prototypes:

RealVector getRowVector(int row) throws MatrixIndexException;

After searching though, I found that Java doesn't have prototypes. What is the purpose of the code above? Is there an actual implementation somewhere?

It's odd because the full implementation for the similar RealVector class is given as I'd expect; it's just RealMatrix that's like this.

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117

1 Answers1

3

RealMatrix is an interface. An interface defines a contract that implementations are responsible for fulfilling, but without providing any implementation code itself (although as of Java8 it can have default methods and static methods). You can use an interface to limit how much a client needs to know about an object it's using. The most basic example is java.util.List, which provides common methods for accessing and modifying lists, and has multiple implementations, some provided in the JDK collections library (one for a list backed by an array, one for a linked list implementation), and some implemented in libraries and frameworks (for instance, Hibernate has its own List implementation facilitating lazy-loading in persistent entities).

The apidoc page lists the implementing classes: AbstractRealMatrix, Array2DRowRealMatrix, BlockRealMatrix, DiagonalMatrix, OpenMapRealMatrix.

Community
  • 1
  • 1
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • Oh Dur! I can't believe I missed that -_-. I actually need to look up the source for `Array2DRealMatrix` (or whatever it's called). Thanks. That's embarrassing. – Carcigenicate Jul 22 '15 at 17:00