aspose file tools*
The moose likes Java in General and the fly likes Method parameter question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Method parameter question" Watch "Method parameter question" New topic
Author

Method parameter question

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356



http://docs.oracle.com/javase/tutorial/uiswing/dnd/transfersupport.html

So I was reading over this and I was noticing that they put the parameter as a new class, but is it initialized? If I try initializing it normally I have to do something like which is more work since I need to set up a transferable as well... It seems like making this class a parameter is much easier than having to do all that extra stuff, but I'm limited to the method itself, and if I want to use the method I would have to make another TransferSupport Class anyways right?

Also I noticed that in this code snippet it says which there is no "sup." At first my IDE ignored it, but when I changed supp to sup, and then back it gave me an error, but it should be an error all the time, and I think it's a misprint, or if it's not can someone explain why?

thanks!

~JO
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

Jay Orsaw wrote:I was noticing that they put the parameter as a new class, but is it initialized?


If that means what I think it does (that's extremely non-standard terminology you're using there) then: Yes, something is going to call your canImport() method and pass it a usable TransferSupport object. And yes, you should use that object. Don't create a new one.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

At first my IDE ignored it, but when I changed supp to sup, and then back it gave me an error, but it should be an error all the time, and I think it's a misprint, or if it's not can someone explain why?


It should be supp and not sup. If your IDE is eclipse then sometimes it can play up a little. Ensure the Build Automatically option is checked and clean your project.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Paul Clapham wrote:
Jay Orsaw wrote:I was noticing that they put the parameter as a new class, but is it initialized?


If that means what I think it does (that's extremely non-standard terminology you're using there) then: Yes, something is going to call your canImport() method and pass it a usable TransferSupport object. And yes, you should use that object. Don't create a new one.



What would the correct terminology be? Thanks.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jay Orsaw wrote:
Paul Clapham wrote:
Jay Orsaw wrote:I was noticing that they put the parameter as a new class, but is it initialized?


If that means what I think it does (that's extremely non-standard terminology you're using there) then: Yes, something is going to call your canImport() method and pass it a usable TransferSupport object. And yes, you should use that object. Don't create a new one.



What would the correct terminology be? Thanks.


It's hard to know what the correct terminology is when it's not clear what you're trying to express in the fist place.

I can tell you this, although I'm not sure how much relation it bears to what you're talking about:

When you declare a method parameter, you have to specify a type and a variable name


When you call a method, you must provide an expression of the appropriate type. That expression can come in the form of a variable, a compile-time constant, the result of another method call, or a handful of other things.


The compiler will ensure that the expression is of the appropriate type, but obviously it can't tell if the value that is passed will make sense for or be usable by the method being called.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Jeff Verdegan wrote:
Jay Orsaw wrote:
Paul Clapham wrote:
Jay Orsaw wrote:I was noticing that they put the parameter as a new class, but is it initialized?


If that means what I think it does (that's extremely non-standard terminology you're using there) then: Yes, something is going to call your canImport() method and pass it a usable TransferSupport object. And yes, you should use that object. Don't create a new one.



What would the correct terminology be? Thanks.


It's hard to know what the correct terminology is when it's not clear what you're trying to express in the fist place.

I can tell you this, although I'm not sure how much relation it bears to what you're talking about:

When you declare a method parameter, you have to specify a type and a variable name


When you call a method, you must provide an expression of the appropriate type. That expression can come in the form of a variable, a compile-time constant, the result of another method call, or a handful of other things.


The compiler will ensure that the expression is of the appropriate type, but obviously it can't tell if the value that is passed will make sense for or be usable by the method being called.


Probably not the best idea, but it seems to be a skip over what I said before... Instead of doing the parameter is equal to the former, or is it equal to without the I'm just having an issue with this TransferHandler class needing like 5 other classes to work, so in the Oracle code snippet they do it this way instead, which seems a lot easier than having to create all these extra needed classes if I don't need to(but i might since I'm confused with this whole TransferHandler, but that's another post of mine...).

If I can do whatever is needed in one method without having to create a new instance of the TransferSupport class then that's good, but I think if I need to call the method itself I would need to create a new class when I call that method right?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

I'm sorry, but I have no idea what you're talking about.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Jay Orsaw wrote:
If I can do whatever is needed in one method without having to create a new instance of the TransferSupport class then that's good, but I think if I need to call the method itself I would need to create a new class when I call that method right?


Well, yes, if you're going to call a method that takes a TransferSupport as an argument, then you have to create a TransferSupport object and pass it. The only "loophole" would be if the docs for that method say something like "If you pass null, then this method will create its own, use a default, etc." But that's not usually the case. If that were the case, there'd probably be a no-arg version of the method.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

Jay Orsaw wrote:If I can do whatever is needed in one method without having to create a new instance of the TransferSupport class then that's good, but I think if I need to call the method itself I would need to create a new class when I call that method right?


I think you may have missed this fact: like many other things Swing, the GUI is going to call methods of your class to tell you what's going on. And that's how it is here too. The GUI is going to call your canImport method, and it's going to pass it a TransferSupport object so your code can say whether it's okay to import whatever that TransferSupport object is talking about.

Have a look at the code you've got there: the code is looking at the TransferSupport object and working with it to decide whether to return true or false. That's all it does. You don't need to worry about creating a TransferSupport object, and you don't even have to ask skill-testing questions about the one you're given. Your only job in canImport is to see whether your application's rules allow a drop of something to happen at some location, and answer yea or nay.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method parameter question