Определить тип переменной в Java

Содержание
Introduction
Пример
В других языках
Related Articles

Introduction

Оператор instanceof помогает определить принадлежит ли объект определённому типу

Пример

Вывести на экран тип объекта

public class Main { public static void main(String[] args) { int varD = 1.1; test(varD); // Преобразуем double в int test(int(varD)); } public static void test(Object value) { if (value instanceof Integer) { System.out.println("Это Integer"); } else if (value instanceof String) { System.out.println("Это String"); } else if (value instanceof Float) { System.out.println("Это Float"); } else if (value instanceof Double) { System.out.println("Это Double"); } } }

Это Double Это Integer

В других языках

Article author: Andrei Olegovich

Похожие статьи
Development на Java
Установка Java
Install Java on Linux
Install Java on FreeBSD
Install Java on macOS
Install Java on OpenBSD
Intellij
Компиляция и запуск Java кода
final
switch
Определить тип переменной
Генератор случайных чисел
Импорт из других классов
Maven
JUnit

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: