<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=Method_Overloading</id>
	<title>Method Overloading - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=Method_Overloading"/>
	<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;action=history"/>
	<updated>2026-05-16T00:05:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0-beta</generator>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;diff=1724&amp;oldid=prev</id>
		<title>Egge at 02:30, 1 October 2007</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;diff=1724&amp;oldid=prev"/>
		<updated>2007-10-01T02:30:39Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 02:30, 1 October 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l49&quot;&gt;Line 49:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 49:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you don&amp;#039;t know all the data type rules in Java, it would be easy to call the wrong function here.  I would go so far as to say the overloading is [http://acmqueue.com/modules.php?name=Content&amp;amp;pa=showpage&amp;amp;pid=315 Syntactic Heroin], but I do think it should only be used to extreme care.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;If you don&amp;#039;t know all the data type rules in Java, it would be easy to call the wrong function here.  I would go so far as to say the overloading is [http://acmqueue.com/modules.php?name=Content&amp;amp;pa=showpage&amp;amp;pid=315 Syntactic Heroin], but I do think it should only be used to extreme care.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Java]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key egge_wikimedia-mw_:diff:1.41:old-1468:rev-1724:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Egge</name></author>
	</entry>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;diff=1468&amp;oldid=prev</id>
		<title>Brianegge at 21:06, 21 July 2006</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;diff=1468&amp;oldid=prev"/>
		<updated>2006-07-21T21:06:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:06, 21 July 2006&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l18&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;I have an object: test2&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;I have an object: test2&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Notice how &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;it calls &lt;/del&gt;the Object &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;method even when passed a String&lt;/del&gt;.  &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The &lt;/del&gt;method dispatch is determined at compile time, and the compiler only sees &#039;test2&#039; as an Object.  It&#039;s a matter of opinion if autovars would improve the situatio.  To make this more confusing, all you have to do is put foo(Object object) in a parent class.  Because collections and iterators always return a type Object, it is  easy to call the wrong function when using collections:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Notice how &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;the third call goes to &lt;/ins&gt;the Object &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function&lt;/ins&gt;.  &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;This is because the &lt;/ins&gt;method dispatch is determined at compile time, and the compiler only sees &#039;test2&#039; as an Object.  It&#039;s a matter of opinion if autovars would improve the situatio.  To make this more confusing, all you have to do is put foo(Object object) in a parent class.  Because collections and iterators always return a type Object, it is  easy to call the wrong function when using collections:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key egge_wikimedia-mw_:diff:1.41:old-1467:rev-1468:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Brianegge</name></author>
	</entry>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;diff=1467&amp;oldid=prev</id>
		<title>Brianegge at 20:06, 21 July 2006</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Method_Overloading&amp;diff=1467&amp;oldid=prev"/>
		<updated>2006-07-21T20:06:29Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Method overloadeding can be a bit tricky in Java, especially with inheritance.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  public void foo(Object object) { System.out.println(&amp;quot;I have an object: &amp;quot; + object); }&lt;br /&gt;
  public void foo(String string) { System.out.println(&amp;quot;I have a string: &amp;quot; + string); }&lt;br /&gt;
  &lt;br /&gt;
  public void testOverloading() {&lt;br /&gt;
    foo(new Object());&lt;br /&gt;
    foo(&amp;quot;test1&amp;quot;);&lt;br /&gt;
    Object test2 = &amp;quot;test2&amp;quot;;&lt;br /&gt;
    foo(test2);&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Yields:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
I have an object: java.lang.Object@be0e27&lt;br /&gt;
I have a string: test1&lt;br /&gt;
I have an object: test2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Notice how it calls the Object method even when passed a String.  The method dispatch is determined at compile time, and the compiler only sees &amp;#039;test2&amp;#039; as an Object.  It&amp;#039;s a matter of opinion if autovars would improve the situatio.  To make this more confusing, all you have to do is put foo(Object object) in a parent class.  Because collections and iterators always return a type Object, it is  easy to call the wrong function when using collections:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  public void testOverloading() {&lt;br /&gt;
    Set set = new HashSet();&lt;br /&gt;
    set.add(new Object());&lt;br /&gt;
    set.add(&amp;quot;test3&amp;quot;);&lt;br /&gt;
    for(Iterator iter = set.iterator(); iter.hasNext(); ) {&lt;br /&gt;
      foo(iter.next());&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Yields:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
I have an object: test3&lt;br /&gt;
I have an object: 3.14&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to have the correct function called, you&amp;#039;ll have to do an instanceof check and some sort of case construct.  In the case above, having multiple overloads of foo isn&amp;#039;t a bad thing, since they do about the same action.  Situations where the actions do something completely different should be avoided.  Here&amp;#039;s a particularly evil example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  public float half(float f) { return f / 2; }&lt;br /&gt;
  public double half(double d) { throw new RuntimeException(&amp;quot;Gotcha!&amp;quot;); }&lt;br /&gt;
&lt;br /&gt;
  public void testOverloading3() {&lt;br /&gt;
    System.out.println(half(3)); &amp;lt;-- this works because 3 gets promoted to a float&lt;br /&gt;
    System.out.println(half(3.0)); &amp;lt;-- this fails because 3.0 is by default a double&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t know all the data type rules in Java, it would be easy to call the wrong function here.  I would go so far as to say the overloading is [http://acmqueue.com/modules.php?name=Content&amp;amp;pa=showpage&amp;amp;pid=315 Syntactic Heroin], but I do think it should only be used to extreme care.&lt;/div&gt;</summary>
		<author><name>Brianegge</name></author>
	</entry>
</feed>