简体   繁体   English

Java:一行中的多次转换

[英]Java: multiple conversions in a single line

Hello StackOverflow community.你好 StackOverflow 社区。

Im making my first steps in Java and OOP.我在 Java 和 OOP 方面迈出了第一步。 I would like to know ¿Is there a way to convert and argument in to another type of variable, then convert it in to an object in a single line of operation?.我想知道 ¿

Thank you for your time and help.感谢您的时间和帮助。

This is the code that isnt mine, it is from a book im reading:这是不是我的代码,它来自我正在阅读的一本书:

public class Changer {
    public static void main(String[] arguments) {
        if (arguments.length > 0) {
            System.out.println("The original value: "
                + arguments[0]);
            Float num1 = new Float(arguments[0]);
            float num2 = num1.floatValue();
            int num3 = (int)num2;
            System.out.println("The final value: " + num3);
        }
    }
}

Boann Answer: float is faster than Float. Boann 答案:float 比 Float 快。 However, since this particular code executes only once, it will take no time either way.但是,由于此特定代码仅执行一次,因此无论哪种方式都不需要时间。 You should only worry about performance of those lines of code that run millions, billions or trillions of times in your program, or when you've benchmarked and determined that there is a real bottleneck.您应该只担心那些在您的程序中运行数百万、数十亿或数万亿次的代码行的性能,或者当您进行基准测试并确定存在真正的瓶颈时。 Anything else is wasting your time as a programmer, while saving no noticeable time in the program.其他任何事情都是在浪费你作为程序员的时间,而在程序中没有明显的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM