A simple question?

Hi Experts, I am a Java Newbie and am just about getting my head around Java Code. I have been looking at some source code available on the net and was wondering if someone could explain this (simply to me). first the code (or part of it(:

-----------------------------------------------------------------------------------------------------------
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileManager
{
  public FileManager() {  }
  public static void setFileTypeAndCreator(String s, long l, long ll) throws IOException {}
  public static void setFileType(String s, long l) throws IOException{}
  public static void setFileCreator(String s, long l) throws IOException{}
  public static long getFileTypes(String filename) throws IOException
  {
    return 0L;
  }
}

---------------------------------------------------------------------------------------------

The question is a simple one. What is the point of having a method for example that (if I understand this correctly), does nothing. For example the:

public static void setFileType(String s, long l) throws IOException{}

What does a method like this actually do? I keep seeing this sort of thing all over the place but I am puzzled as to what it is meant to achieve -- any help appreciated.


zaphod_beeblebroxAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
It's there so it can be overridden and implemented in a subclass or becuase it requires an implementation to fulfil an interface or abstract class
0
 
girionisCommented:
>
> The question is a simple one. What is the point of having a method for
> example that (if I understand this correctly), does nothing. For example the:

> public static void setFileType(String s, long l) throws IOException{}

> What does a method like this actually do? I keep seeing this sort of
> thing all over the place but I am puzzled as to what it is meant to
> achieve -- any help appreciated.

Where did you get the code above? It is pointless to have it the way it is, you are right. However is you had an intereface where you need to implement you would need to provide implementations of the methods defined in the interface, even if they do nothing at all, so you coudl have somethign like the above.
0
 
armoghanCommented:
This class seems to be kind of Adaptor class which implements method with nothing in it.
When you extend from these classes you override these functions and provide implementation
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
girionisCommented:
Or maybe this is a generic class and the subclasses need to extend it, but again you do not extend any functionallity, so it's pointless I'd say.
0
 
girionisCommented:
It would be better for the class to have been decalred abstract I reckon.
0
 
zaphod_beeblebroxAuthor Commented:
Hell guys, that was quick. I just wanted to know if the code made any sense as it was. I am awarding the points to CEHJ because his answers makes the most sense to me, but all your answers are good and much appreciated
0
 
CEHJCommented:
>>It would be better for the class to have been decalred abstract I reckon.

Indeed. It's obviously been written by someone who doesn't understand interfaces/abstract classes
0
 
CEHJCommented:
:-)
0
All Courses

From novice to tech pro — start learning today.