<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://java.dzone.com"  xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dz="http://www.developerzone.com/modules/dz/1.0">
<channel>
 <title>Javalobby - Comments for &quot;Borrowing Language Features - Default Argument Values in Java&quot;</title>
 <link>http://java.dzone.com/news/default-argument-values-java</link>
 <description>Comments for &quot;Borrowing Language Features - Default Argument Values in Java&quot;</description>
 <language>en</language>
<item>
 <title>But it would impact</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2193</link>
 <description>&lt;!--paging_filter--&gt;But it would impact performance when passing primitives.</description>
 <pubDate>Sat, 29 Mar 2008 12:09:59 -0400</pubDate>
 <dc:creator>okidoky</dc:creator>
 <guid isPermaLink="false">comment 2193 at http://java.dzone.com</guid>
</item>
<item>
 <title>The idea for optional</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2191</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;The idea for optional parameters is not new and has been discussed in many variations. The comments I&#039;ve read mix up two things (that maybe related though): optional parameters and readability (e.g. named parameters). &lt;/p&gt;&lt;p&gt;Current Java already has &amp;quot;optional&amp;quot; parameters in form of Varargs. The naive approach (no language change) would be to pass optional parameters within that Vararg and unpack them at method side. This would of course cause a lot of boiler plate and it&#039;s not type safe.&lt;/p&gt;One could make the compiler handle that boilerplate and interpret defaulted parameters as part of a Varargs parameter. The compiler would wrap arguments into the Vararg array at invocation time (including autoboxing primitives to allow for null) and unwrap those arguments having a corresponding parameter within the invoked method. This would overcome some of the issues mentioned wrt. signature changes and be compatible to current Java at bytecode level.</description>
 <pubDate>Sat, 29 Mar 2008 05:38:48 -0400</pubDate>
 <dc:creator>stefan.schulz</dc:creator>
 <guid isPermaLink="false">comment 2191 at http://java.dzone.com</guid>
</item>
<item>
 <title>I ran into the following</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2175</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;I ran into the following problem before when I was trying to argue for named arguments.  eg:&lt;/p&gt;&lt;p&gt;&amp;lt;code&amp;gt;&lt;br /&gt;int method(int x = 0, int y = 0, int w = 320, int h=240)&lt;br /&gt;...&lt;br /&gt;method(w: 640, h: 480);&lt;br /&gt;&amp;lt;/code&amp;gt;&lt;/p&gt;&lt;p&gt;In addition to the default arguments, it makes it very clear what parameters you&#039;re trying to pass in.&lt;/p&gt;&lt;p&gt;Great alternative to calls like this: something(0, null, null, null, 0, &amp;quot;something&amp;quot;, &amp;quot;something else&amp;quot;).&lt;br /&gt;What the heck is what?&lt;/p&gt;&lt;p&gt;But, one of the problems was that where should the code go where the default is set?  The method or the calling method?  If it goes in the calling method, then the default value needs to described in the class file.  It could be annotation that an updated javac compiler would automatically create for you I suppose.&lt;/p&gt;&lt;p&gt;But what if that third party library changes and the default parameter changes.  Or what if the default parameter is removed and is not optional anymore?  Now you have code that still runs, but can&#039;t be recompiled.&lt;/p&gt;&lt;p&gt;There were some other arguments against it, one in particular, just can&#039;t remember what... &lt;/p&gt;</description>
 <pubDate>Fri, 28 Mar 2008 14:36:53 -0400</pubDate>
 <dc:creator>okidoky</dc:creator>
 <guid isPermaLink="false">comment 2175 at http://java.dzone.com</guid>
</item>
<item>
 <title>Personally I prefer using</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2169</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Personally I prefer using overloading to fake the default argument property simply because it requires less work from the caller whereas the null checking solution requires the same amount of work from the caller to call the method: &lt;/p&gt;&lt;pre class=&quot;java&quot;&gt;methodA(null,null,null);&lt;/pre&gt;&lt;p&gt;and in my opinion, passing null values to methods makes it harder to understand the code. I agree that it need not be an all or nothing approach - It could simply be that default values are allowed for anything that can be defined as a literal (as in the restriction that a vararg must be the last parameter). However, I also don&#039;t see why you could not specify default values by calling a constructor explicitly:&lt;/p&gt;&lt;br /&gt;&lt;pre class=&quot;java&quot;&gt;void methodA(Date date = new Date()) {}&lt;br /&gt;&lt;br /&gt;void methodB(Person p = new Person(&amp;quot;John&amp;quot;, &amp;quot;Doe&amp;quot;)) {} &lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
 <pubDate>Fri, 28 Mar 2008 13:09:24 -0400</pubDate>
 <dc:creator>hb14717</dc:creator>
 <guid isPermaLink="false">comment 2169 at http://java.dzone.com</guid>
</item>
<item>
 <title>Maybe we don&#039;t need the</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2168</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Maybe we don&#039;t need the ultimate flexibility on this one. Maybe only immutable objects, like for default values in annotations, and/or require a final method declararion.&lt;/p&gt;&lt;p&gt;Cheers&lt;br /&gt;Mikael&lt;/p&gt;</description>
 <pubDate>Fri, 28 Mar 2008 12:46:48 -0400</pubDate>
 <dc:creator>mgrev</dc:creator>
 <guid isPermaLink="false">comment 2168 at http://java.dzone.com</guid>
</item>
<item>
 <title>I agree about borrowing</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2160</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;I agree about borrowing useful features from other languages,  but not this one :)&lt;/p&gt;&lt;p&gt; default arguments are handy when it comes to primitives which are passed by value, and also to immutable objects like String in your example.&lt;/p&gt;&lt;p&gt; but how do you want it to work for normal mutable objects?&lt;/p&gt;&lt;p&gt; should a new object be created automatically? if yes , which constructor to use&lt;/p&gt;&lt;p&gt;so I think default arguments is really asking for troubles&lt;/p&gt;&lt;p&gt;The alternative is to do something like this, it might not be very readible but at least you have control:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class=&quot;java&quot;&gt;public void methodA(String arg1, String arg2, String arg3) {  
arg3=  arg3 != null ? arg3 : &amp;quot;default&amp;quot;;    
}  
 
&lt;/pre&gt;&lt;p&gt;The overloading is also okay but in case you need default values for multiple arguments you will end up creating having many methods with  all possible combination of default arguments, for the example you use imagine you want to have a default value for the 3 arguments. you will end up with this&lt;/p&gt;&lt;p&gt;public void methodA(A arg1) {  }&lt;br /&gt;public void methodA( B arg2,) {  }&lt;br /&gt;public void methodA(C arg3) {  }&lt;br /&gt;public void methodA(A arg1, B arg2) {  }&lt;br /&gt;public void methodA(A arg1, C arg3) {  }&lt;br /&gt;public void methodA( B arg2, C arg3) {  }&lt;br /&gt;public void methodA(A arg1, B arg2, C arg3) {  }&lt;/p&gt;&lt;p&gt; imagine with four arguments!&lt;/p&gt;&lt;p&gt; this is probably easier although not very sexy&lt;/p&gt;&lt;pre&gt;public void methodA(A arg1, B arg2, C arg3) {  

arg1=  arg1 != null ? arg1 : new A();
arg2=  arg2 != null ? arg2 :  new B();
arg3=  arg3 != null ? arg3 : &amp;quot;new C();


}&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
 <pubDate>Fri, 28 Mar 2008 11:52:00 -0400</pubDate>
 <dc:creator>knasser</dc:creator>
 <guid isPermaLink="false">comment 2160 at http://java.dzone.com</guid>
</item>
<item>
 <title>Microsoft docs: Use method</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2159</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;Microsoft docs:&lt;/p&gt;&lt;p&gt; Use method overloading instead of allowing default arguments. Default arguments do not version well and therefore are not allowed in the Common Language Specification (CLS).&lt;/p&gt;&lt;p&gt; From here: http://msdn2.microsoft.com/en-us/library/xxfyae0c(VS.71).aspx&lt;/p&gt;&lt;p&gt; I seem to remember some programming puzzlers from people who combined method overloading and default arguments in C++.&lt;/p&gt;</description>
 <pubDate>Fri, 28 Mar 2008 11:11:19 -0400</pubDate>
 <dc:creator>mt79448</dc:creator>
 <guid isPermaLink="false">comment 2159 at http://java.dzone.com</guid>
</item>
<item>
 <title>There is one quite important</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2158</link>
 <description>&lt;!--paging_filter--&gt;&lt;p&gt;There is one quite important difference between java and other languages as far as default arguments are concerned. In all the other cases (I know about), default arguments are resolved on compile time (so it is just compiler trickery, which inserts missing arguments behind the scenes). To follow &#039;java way&#039; default arguments in java would have to work differently - you would be really calling function with some arguments missing and they would be filled out at call/link time.&lt;/p&gt;&lt;p&gt;Why it makes a difference? Think about 3rd party library, exporting function doSomething(String name). In next release, they want to add doSomething(String name, boolean ignoreCase = false). Currently, they will just export two methods (one for backward compatibility). With java style defaults, they can just change the function by adding a parameter with default value and all existing program will continue to work. &lt;/p&gt;&lt;p&gt;Unfortunately, to get a full power of that, we need named arguments - and named arguments are not so easy to get inside &#039;mature&#039; language. I would prefer to rather wait some more time for named arguments, rather than having C++ style, compile-time only defaults soon. &lt;/p&gt;</description>
 <pubDate>Fri, 28 Mar 2008 10:31:32 -0400</pubDate>
 <dc:creator>abies</dc:creator>
 <guid isPermaLink="false">comment 2158 at http://java.dzone.com</guid>
</item>
<item>
 <title>My thoughts on this topic is</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2154</link>
 <description>&lt;!--paging_filter--&gt;My thoughts on this topic is exactly like yours. The java developers I&#039;ve discussed this with tend to agree with that view or tend not to mind it either way. I&#039;m hoping there&#039;s some good responses that indicate why such a feature should not be allowed.</description>
 <pubDate>Fri, 28 Mar 2008 09:32:39 -0400</pubDate>
 <dc:creator>hb14717</dc:creator>
 <guid isPermaLink="false">comment 2154 at http://java.dzone.com</guid>
</item>
<item>
 <title>Yes!!  I really want this</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2153</link>
 <description>&lt;!--paging_filter--&gt;Yes!!  I really want this as well. It would clean up a lot of APIs, new ones at least. A no-brainer to me.</description>
 <pubDate>Fri, 28 Mar 2008 09:30:30 -0400</pubDate>
 <dc:creator>mgrev</dc:creator>
 <guid isPermaLink="false">comment 2153 at http://java.dzone.com</guid>
</item>
<item>
 <title>I would rather have this</title>
 <link>http://java.dzone.com/news/default-argument-values-java#comment-2147</link>
 <description>&lt;!--paging_filter--&gt;I would rather have this than almost every other &amp;quot;new feature&amp;quot; suggested so far...  It&#039;s the one thing I *still* miss from my Delphi days (and that was almost 10 years ago)</description>
 <pubDate>Fri, 28 Mar 2008 07:36:42 -0400</pubDate>
 <dc:creator>bloid</dc:creator>
 <guid isPermaLink="false">comment 2147 at http://java.dzone.com</guid>
</item>
</channel>
</rss>
