0

I am trying to convert some Java to C# and I have a line as follows:

int[][] variableName = get();

What my question is is what does "get();" actually do? There is no function or method in the Java code I am converting called "get()" so I am assuming "get();" simply creates an empty object of the required type, in this case, an empty int[][]. Would I be correct in this assumption or does "get()" in Java have some other meaning?

I have searched for "get()" within stackoverflow but the () are ignored and as a result I get masses of information about HTTP GET which is not what I'm after so excuse me if this is duplicated anywhere else.

All help appreciated.

adelphiaUK
  • 49
  • 1
  • 7
  • Perhaps it's a method declared in the calling class. Are you sure you looked correctly? – Yuval Itzchakov Oct 14 '15 at 11:18
  • well, `get` just looks like a method call from the current class... – SomeJavaGuy Oct 14 '15 at 11:18
  • Or, it's an inherited method from a parent class. – Tunaki Oct 14 '15 at 11:21
  • 3
    Are you using an IDE? In that case, you can probably just right-click `get` and 'go to declaration' or something. Or even just hover over it with your mouse. – Dennis_E Oct 14 '15 at 11:22
  • Check parent classes, it can be there as well. Looks like a static method. – Chetan Gole Oct 14 '15 at 11:26
  • @ChetanGole: *"Looks like a static method"* Would that that were true. A *huge* number of Java programmers choose to leave `this.` off even when dealing with instance methods and fields. – T.J. Crowder Oct 14 '15 at 11:30
  • 1
    If it's not in the class or in any superclass, it might be a statically imported method from another class. There would be an `import static ...;` statement at the top of the source file in that case. – Jesper Oct 14 '15 at 12:07

1 Answers1

3

There is no function or method in the Java code I am converting called "get()"

There must be, either in that class or one of its superclasses, or as a static import although that's not very likely. (Nice one, Jesper!) My guess is that you haven't checked all of the superclasses.

...so I am assuming "get();" simply creates an empty object of the required type, in this case, an empty int[][]. Would I be correct in this assumption or does "get()" in Java have some other meaning?

No, unlike C#, get is not a keyword and has no special meaning in Java. That line of code calls a method called get (it could just as easily be called foo) which is declared in the class or one of its superclasses. It may be a static or instance method, but it will be defined by the class or one of its superclasses, or as a static import.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I am using NetBeans and I'm used to using VS but using what @Dennis_E suggested, the import is from SwingWorker.java which isn't part of the code directly (hence why I couldn't find it with a search of the code). Apparently it returns future.get() which is a FutureTask, so now I have a starting point of figuring out how to implement this. Thanks all! – adelphiaUK Oct 14 '15 at 15:05