# Automatic type conversion?

**URL:** https://discourse.processing.org/t/automatic-type-conversion/17175
**Category:** Beginners
**Created:** [January 19, 2020, 1:25am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175 "2020-01-19T01:25:35Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![beckerc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/beckerc/32/3511_2.png) [@beckerc](https://discourse.processing.org/u/beckerc)
#### Post date: [January 19, 2020, 1:25am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/1 "2020-01-19T01:25:35Z")

</div>

The parameters for ellipse() are all of type float ([https://processing.org/reference/ellipse\_.html](https://processing.org/reference/ellipse_.html)). Why does this work when I pass in all ints? Is there type conversion happening in the background? I have been using these 2D shapes for years but never realized that the parameter types are floats.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 19, 2020, 1:38am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/2 "2020-01-19T01:38:22Z")

</div>

> [@beckerc](#):
>
> Is there type conversion happening in the background?

- Java simply upgrades a passed argument to a `float` if it isn’t already.
- What Java won’t do is downgrade a `double` to a `float` though!
- So something like this won’t compile: `ellipse(56d, 46, 55, 55);`.
- Notice the literal `56` got a `d` suffix on it, meaning it is of datatype `double`.
- The only exception I can remember now where Java can downgrade a primitive datatype is when we use 1 of its composite assignment operators such as `+=`, `/=`, `^=`, etc.:  
[+= (add assign) / Reference / Processing.org](http://Processing.org/reference/addassign.html)

```auto
int a = 10;
a *= PI;
println(a); // 31 instead of 31.415928
exit();

```

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [January 19, 2020, 4:36am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/3 "2020-01-19T04:36:42Z")

</div>

I’ve seen this fail in constructors sometimes though. If you declare float in a constructor and pass an int it will often prompt you to pass a float.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 19, 2020, 4:54am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/4 "2020-01-19T04:54:03Z")

</div>

> [@paulgoux](#):
>
> … it will often prompt you to pass a `float`.

Prompt? Who exactly does it? Never seen it and it has never failed on me! 😕

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [January 19, 2020, 4:55am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/5 "2020-01-19T04:55:21Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9ac2c2da90e398da2c7430fdd56fa51a21c67e7b.png)

this is in a method, but it does it with my slider and menu constructors too.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 19, 2020, 5:01am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/6 "2020-01-19T05:01:04Z")

</div>

That’s some kinda strange warning, not an error! 😐

Anyways, I didn’t even know about it b/c 1 of the 1st things I do when I install Processing is turn off “Continuously check for errors” option within the PDE’s “Preferences”. 😉

I just can’t stand that feature nagging me all the time while I type in! 🤮

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [January 19, 2020, 5:03am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/7 "2020-01-19T05:03:45Z")

</div>

just tried to disable it, and it still shows the message and refuses to load the sketch.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/453880cc68f2d8837d062f84662a60b75d6fb5ef.png)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 19, 2020, 5:07am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/8 "2020-01-19T05:07:31Z")

</div>

- Paying more attention now I’ve found out what’s wrong there.
- It’s requesting a Float instead of a `float`!
- Java will fail to auto-coerce a non-corresponding primitive value on such situation.

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [January 19, 2020, 5:11am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/9 "2020-01-19T05:11:00Z")

</div>

awesome I failed to realise something so simple. Btw why do the two types exist, I understand that when declaring floats in a array or arrayList it has to be done, but when you are new it hard to find explanations behind the reason for this.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 19, 2020, 5:17am UTC](https://discourse.processing.org/t/automatic-type-conversion/17175/10 "2020-01-19T05:17:17Z")

</div>

> [@paulgoux](#):
>
> , I understand that when declaring floats in an array or ArrayList it has to be done,

For the ArrayList indeed. But vanilla arrays are more than OK w/ all 8 Java primitive datatypes.

> [@paulgoux](#):
>
> BtW, why do the two types exist,

B/c Java generics, the 1s inside the “diamond” `<>`, can’t have any of the 8 primitive datatypes!

So we use the corresponding wrapper classes instead:  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Number.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Number.html)  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Float.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Float.html)
