Java字符串方法编译 [英] Java string method compilation

查看:216
本文介绍了Java字符串方法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java String语法有疑问.Java有一个函数将字符转换为小写字母为String.toLowerCase(),它返回一个带有小写字符的字符串。但是如果我们不指定上面的方法到一个String变量,如:



I have a doubt in Java String syntax.. Java has a function for converting characters to lower case as String.toLowerCase() which "returns a String" with lower case characters.. But if we do not assign the above method to a String variable like:

String a = "aBCd";




a.toLowerCase(); // Do not cause any compilation error





正确的方式





Correct Way

a = a.toLowerCase(); // a is assigned the value of updated string





为什么第一个声明不会导致任何编译错误?



我尝试了什么:



理解Java中的字符串方法..



Why does the first declaration not cause any compilation error?

What I have tried:

Understanding string method in Java..

推荐答案

因为你只是调用一个方法,这是在几乎所有计算机语言中语法都正确。您不选择保存返回值的事实是您作为开发人员的选择。毕竟,编译器几乎总是假设您知道自己在做什么。
Because you are just calling a method, which is syntactically correct in almost all computer languages. The fact that you do not save the returned value is your choice as the developer. After all, the compiler almost always assumes that you know what you are doing.


这篇关于Java字符串方法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆