Question Details

No question body available.

Tags

java c

Answers (9)

February 23, 2026 Score: 3 Rep: 37,276 Quality: Medium Completeness: 50%

Java is very different than C.
In general when asking here it is better to focus on one language.

Anyway in this case in both languages you can see what type a function/method return by reviewing its declaration/signature or definition (either in the documentation or with the help of your editor/IDE).

For example (in C) if you have a function declared as:

double f(int n);

It is clear f returns a value of type double (you can also see that it expects an argument - n - of type int).

February 23, 2026 Score: 3 Rep: 1 Quality: Low Completeness: 0%

we can check function signature.

February 23, 2026 Score: 2 Rep: 13,223 Quality: Low Completeness: 20%

Java is a strongly typed language. Every method has a 'signature', which details the arguments to be passed to the method and a type for the return of the method. The language does not allow the method to return any other type, so the type in the signature is accurate. The method called would not have compiled if it returned anything else.

C is not strongly typed; its typing is intentionally weak, since it was intended to be a structured assembler, not a high level language. Its functions have signatures also, but they're on the level of suggestions, and the person writing the function could have returned any data type. There are many 'lint'-type checkers and so forth that could warn the function author if he had cared to use them, and the compiler will warn him about some, but in calling the routine you have to be aware it is much easier for the author to have returned something different than the signature indicates.

February 23, 2026 Score: 1 Rep: 13,223 Quality: Low Completeness: 0%

I don't see any value in this -- the method called must return a value that matches its method signature type. And you cannot call getClass() on an int, long, or float at all.

February 23, 2026 Score: 1 Rep: 122,730 Quality: Low Completeness: 0%

The function signature tells you what data type it returns. You need to look at the signature in the documentation or in the header file before you can use the function.

February 23, 2026 Score: 0 Rep: 1 Quality: Low Completeness: 30%

In Java you can use the getClass() - method and check if its a java.lang.Integer object and in c you can use typeof to determin the type.

February 23, 2026 Score: 0 Rep: 260 Quality: Low Completeness: 50%

Indeed. Note that while its possible to write a pandora's box method that can return a swamp of different things -

public static Object pandorasBox(){
  Random r = new Random();
  switch(r.nextInt() % 6){
    case 0: return r.nextInt();
    case 1: return r.nextBoolean();
    case 2: return new javax.cryptography.SecureRandom();
    case 3: return new javax.swing.JFrame();
    case 4: return "foobar";
    case 5: return new java.util.ArrayList();
    default: return null;
  }
}

such a method is generally indicative of a design smell (unless this is a contrieved study task so students lean the instanceof keyword)

February 23, 2026 Score: 0 Rep: 11,519 Quality: Low Completeness: 30%

Slightly off-topic but int.class is a thing, despite a lack of a #getClass() to retrieve it.

February 23, 2026 Score: 0 Rep: 392,187 Quality: Low Completeness: 40%

The term "strongly-typed" is meaningless. Or more specifically, it has so many definitions that it's a useless term. To wit, the materials I read before I read the linked post always referred to C as a strongly-typed language. Say what you want to say without using the term "strongly-typed" because that just adds confusion.

And what you say about C is complete bullocks. In C like in Java, the value returned by a function is always of the type the function is declared to return.