# How find the Class of argument when this one is a primitive?

**URL:** <https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970>\
**Category:** Beginners\
**Created:** [April 4, 2019, 5:27pm UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970 "2019-04-04T17:27:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 4, 2019, 5:27pm UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/1 "2019-04-04T17:27:18Z")

</div>

I try to check the class of argument to create a method builder, but when the case the argument is primitive, i don’t find a way to do that ?

My code who’s don’t work !!!

```auto
void setup() {
  Truc t = new Truc();
  println(t.getClass());
  println(t.getClass().getCanonicalName());
  println(t.getClass().getName());
  
  
  int value = 0;
  println(value.equals(int.class));
  println(value == Integer.TYPE);
  println(value.isPrimitive());
  println(value.getClass());
}

class Truc {
}

```

---

<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:** [April 4, 2019, 6:28pm UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/2 "2019-04-04T18:28:24Z")

</div>

The 8 Java primitive datatypes aren’t objects/references/pointers in any way. 🐒  
They’ve got no members & the access `.` operator can’t be used on them! 🚫

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 4, 2019, 7:46pm UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/3 "2019-04-04T19:46:01Z")

</div>

Damn it !!! That’s was to make a system for the callback… That’s possible with Java 11 ? Because I believe the next Processing have a chance to turn with Java 11.

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 5, 2019, 7:58am UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/4 "2019-04-05T07:58:39Z")

</div>

Finally I find a way to test :

```auto
int val = 1;
void setup() {
  test(val);
}
void test(Object obj) {
  println(obj.getClass());
}
// print: class java.lang.Integer

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 5, 2019, 8:48am UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/5 "2019-04-05T08:48:08Z")

</div>

Of int there exists a object Int that I use in several places or Integer

---

<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:** [April 5, 2019, 9:20am UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/6 "2019-04-05T09:20:31Z")

</div>

> [@Stanlepunk](#):
>
> `// print: class java.lang.Integer`

Notice that datatype Integer isn’t the same as the primitive datatype `int` . 🙅‍♂️

Rather it’s an object wrapper/box for an `int` primitive value: 📥  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Integer.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Integer.html)

The actual class that’d represent an `int` is _int.class_, not _Integer.class_. 🧐

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 5, 2019, 9:43am UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/7 "2019-04-05T09:43:23Z")

</div>

At the end `class.int` and `class java.lang.Integer` can do a same job ? if Yes that’s ok for me.

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [April 5, 2019, 9:44am UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/8 "2019-04-05T09:44:11Z")

</div>

> [@Chrisir](#):
>
> Of int there exists a object Int that I use in several places or Integer

Don’t understand what you mean ?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 5, 2019, 5:59pm UTC](https://discourse.processing.org/t/how-find-the-class-of-argument-when-this-one-is-a-primitive/9970/9 "2019-04-05T17:59:21Z")

</div>

never mind

Chrisir

…
