java用this->_java中this的用法,直接用this.abc()就可以了

本文介绍了Java中this关键字的用法。this可指自己所在的对象,调用自身方法或变量。通过示例展示了this的三种用法:表示对当前对象的引用;区分成员变量和函数参数;在构造方法中引用满足指定参数类型的构造器,且this不能用在static方法中。

一、指自己所在的对象。比如在一个方法中,调用其他对象的变量或方法时,可以使用那个对象的对象名,比如aa.abc();而调用自己所在对象的方法或变量时,不知道别人给起了什么名,所以直接用this.abc()就可以了。二、看一个小例子中“this”的用法!/*** @author fengzhi-neusoft** 本示例为了说明this的三种用法!*/package test;public class ThisTest {private int i=0;//第一个构造器:有一个int型形参ThisTest(int i){this.i=i+1;//此时this表示引用成员变量i,而非函数参数iSystem.out.println("Int constructor i——this.i: "+i+"——"+this.i);System.out.println("i-1:"+(i-1)+"this.i+1:"+(this.i+1));//从两个输出结果充分证明了i和this.i是不一样的!}// 第二个构造器:有一个String型形参ThisTest(String s){System.out.println("String constructor: "+s);}// 第三个构造器:有一个int型形参和一个String型形参ThisTest(int i,String s){this(s);//this调用第二个构造器//this(i);/*此处不能用,因为其他任何方法都不能调用构造器,只有构造方法能调用他。但是必须注意:就算是构造方法调用构造器,也必须为于其第一行,构造方法也只能调用一个且仅一次构造器!*/this.i=i++;//this以引用该类的成员变量System.out.println("Int constructor: "+i+"/n"+"String constructor: "+s);}public ThisTest increment(){this.i++;return this;//返回的是当前的对象,该对象属于(ThisTest)}public static void main(String[] args){ThisTest tt0=new ThisTest(10);ThisTest tt1=new ThisTest("ok");ThisTest tt2=new ThisTest(20,"ok again!");System.out.println(tt0.increment().increment().increment().i);//tt0.increment()返回一个在tt0基础上i++的ThisTest对象,//接着又返回在上面返回的对象基础上i++的ThisTest对象!}}运行结果:Int constructor i——this.i: 10——11String constructor: okString constructor: ok again!Int constructor: 21String constructor: ok again!14细节问题注释已经写的比较清楚了,总结一下,其实this主要要三种用法:1、表示对当前对象的引用!2、表示用类的成员变量,而非函数参数,注意在函数参数和成员变量同名是进行区分!其实这是第一种用法的特例,比较常用,所以那出来强调一下。3、用于在构造方法中引用满足指定参数类型的构造器(其实也就是构造方法)。但是这里必须非常注意:只能引用一个构造方法且必须位于开始!还有就是注意:this不能用在static方法中!所以甚至有人给static方法的定义就是:没有this的方法!虽然夸张,但是却充分说明this不能在static方法中使用!

c@abc-virtual-machine:~/catkin_ws$ catkin_make_isolated --cmake-args -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules Base path: /home/abc/catkin_ws Source space: /home/abc/catkin_ws/src Build space: /home/abc/catkin_ws/build_isolated Devel space: /home/abc/catkin_ws/devel_isolated Install space: /home/abc/catkin_ws/install_isolated Additional CMake Arguments: -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ traversing 3 packages in topological order: ~~ - drone_control ~~ - mavros_px4_launch ~~ - px4 (plain cmake) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The packages or cmake arguments have changed, forcing cmake invocation ==> Processing catkin package: 'drone_control' ==> cmake /home/abc/catkin_ws/src/drone_control -DCATKIN_DEVEL_PREFIX=/home/abc/catkin_ws/devel_isolated/drone_control -DCMAKE_INSTALL_PREFIX=/home/abc/catkin_ws/install_isolated -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules -G Unix Makefiles in '/home/abc/catkin_ws/build_isolated/drone_control' -- Using CATKIN_DEVEL_PREFIX: /home/abc/catkin_ws/devel_isolated/drone_control -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/abc/catkin_ws/build_isolated/drone_control/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- Configuring done -- Generating done -- Build files have been written to: /home/abc/catkin_ws/build_isolated/drone_control ==> make -j2 -l2 in '/home/abc/catkin_ws/build_isolated/drone_control' <== Finished processing package [1 of 3]: 'drone_control' ==> Processing catkin package: 'mavros_px4_launch' ==> Building with env: '/home/abc/catkin_ws/devel_isolated/drone_control/env.sh' ==> cmake /home/abc/catkin_ws/src/mavros_px4_launch -DCATKIN_DEVEL_PREFIX=/home/abc/catkin_ws/devel_isolated/mavros_px4_launch -DCMAKE_INSTALL_PREFIX=/home/abc/catkin_ws/install_isolated -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules -G Unix Makefiles in '/home/abc/catkin_ws/build_isolated/mavros_px4_launch' -- Using CATKIN_DEVEL_PREFIX: /home/abc/catkin_ws/devel_isolated/mavros_px4_launch -- Using CMAKE_PREFIX_PATH: /home/abc/catkin_ws/devel_isolated/drone_control;/opt/ros/noetic -- This workspace overlays: /home/abc/catkin_ws/devel_isolated/drone_control;/opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/abc/catkin_ws/build_isolated/mavros_px4_launch/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'system_lib' but neither 'system_lib_INCLUDE_DIRS' nor 'system_lib_LIBRARIES' is defined. Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package) CMakeLists.txt:105 (catkin_package) -- Configuring done -- Generating done -- Build files have been written to: /home/abc/catkin_ws/build_isolated/mavros_px4_launch ==> make -j2 -l2 in '/home/abc/catkin_ws/build_isolated/mavros_px4_launch' <== Finished processing package [2 of 3]: 'mavros_px4_launch' ==> Processing plain cmake package: 'px4' ==> Building with env: '/home/abc/catkin_ws/devel_isolated/mavros_px4_launch/env.sh' ==> cmake /home/abc/catkin_ws/src/PX4-Autopilot -DCMAKE_INSTALL_PREFIX=/home/abc/catkin_ws/devel_isolated/px4 -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules -G Unix Makefiles in '/home/abc/catkin_ws/build_isolated/px4/devel' -- PX4 version: v1.16.0-rc1-452-g78a2a3d0dd (1.16.0) -- PX4 config file: /home/abc/catkin_ws/src/PX4-Autopilot/boards/px4/sitl/default.px4board -- PLATFORM posix -- ROMFSROOT px4fmu_common -- TESTING y -- ETHERNET y -- ROOT_PATH . -- PARAM_FILE /fs/mtd_params -- PX4 config: px4_sitl_default -- PX4 platform: posix -- PX4 lockstep: enabled -- cmake build type: RelWithDebInfo -- ccache enabled (export CCACHE_DISABLE=1 to disable) -- Could NOT find gz-transport (missing: gz-transport_DIR) -- Gazebo simulation bridge module disabled: missing dependencies -- Could NOT find gz-transport (missing: gz-transport_DIR) -- Could NOT find gz-sim (missing: gz-sim_DIR) -- Could NOT find gz-sensors (missing: gz-sensors_DIR) -- Could NOT find gz-plugin (missing: gz-plugin_DIR) -- Found DART: /usr/include (Required is at least version "6.6") found components: dart -- Looking for ignition-math6 -- found version 6.15.1 -- Searching for dependencies of ignition-math6 -- Looking for OGRE... -- Found Ogre Ghadamon (1.9.0) -- Found OGRE: optimized;/usr/lib/x86_64-linux-gnu/libOgreMain.so;debug;/usr/lib/x86_64-linux-gnu/libOgreMain.so -- Looking for OGRE_Paging... -- Found OGRE_Paging: optimized;/usr/lib/x86_64-linux-gnu/libOgrePaging.so;debug;/usr/lib/x86_64-linux-gnu/libOgrePaging.so -- Looking for OGRE_Terrain... -- Found OGRE_Terrain: optimized;/usr/lib/x86_64-linux-gnu/libOgreTerrain.so;debug;/usr/lib/x86_64-linux-gnu/libOgreTerrain.so -- Looking for OGRE_Property... -- Found OGRE_Property: optimized;/usr/lib/x86_64-linux-gnu/libOgreProperty.so;debug;/usr/lib/x86_64-linux-gnu/libOgreProperty.so -- Looking for OGRE_RTShaderSystem... -- Found OGRE_RTShaderSystem: optimized;/usr/lib/x86_64-linux-gnu/libOgreRTShaderSystem.so;debug;/usr/lib/x86_64-linux-gnu/libOgreRTShaderSystem.so -- Looking for OGRE_Volume... -- Found OGRE_Volume: optimized;/usr/lib/x86_64-linux-gnu/libOgreVolume.so;debug;/usr/lib/x86_64-linux-gnu/libOgreVolume.so -- Looking for OGRE_Overlay... -- Found OGRE_Overlay: optimized;/usr/lib/x86_64-linux-gnu/libOgreOverlay.so;debug;/usr/lib/x86_64-linux-gnu/libOgreOverlay.so -- Looking for ignition-math6 -- found version 6.15.1 -- Looking for ignition-transport8 -- found version 8.5.1 -- Searching for dependencies of ignition-transport8 -- Config-file not installed for ZeroMQ -- checking for pkg-config -- Checking for module 'libzmq >= 4' -- Found libzmq , version 4.3.2 -- Checking for module 'uuid' -- Found uuid, version 2.34.0 -- Looking for ignition-msgs5 -- found version 5.11.1 -- Searching for dependencies of ignition-msgs5 -- Looking for ignition-math6 -- found version 6.15.1 -- Checking for module 'tinyxml2' -- Found tinyxml2, version 6.2.0 -- Looking for ignition-msgs5 -- found version 5.11.1 -- Looking for ignition-common3 -- found version 3.17.1 -- Searching for dependencies of ignition-common3 -- Looking for dlfcn.h - found -- Looking for libdl - found -- Searching for <ignition-common3> component [graphics] -- Looking for ignition-common3-graphics -- found version 3.17.1 -- Searching for dependencies of ignition-common3-graphics -- Looking for ignition-math6 -- found version 6.15.1 -- Looking for ignition-fuel_tools4 -- found version 4.9.2 -- Searching for dependencies of ignition-fuel_tools4 -- Checking for module 'jsoncpp' -- Found jsoncpp, version 1.7.4 -- Checking for module 'yaml-0.1' -- Found yaml-0.1, version 0.2.2 -- Checking for module 'libzip' -- Found libzip, version 1.5.1 -- Looking for ignition-common3 -- found version 3.17.1 -- Looking for ignition-math6 -- found version 6.15.1 -- Looking for ignition-msgs5 -- found version 5.11.1 -- Found gazebo-classic 11.15.1, including sitl_gazebo-classic simulator and gazebo-classic targets -- Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE) -- ROMFS: ROMFS/px4fmu_common CMake Error at CMakeLists.txt:478 (include): include could not find load file: doxygen Architecture: amd64 ==> CPACK_INSTALL_PREFIX = @DEB_INSTALL_PREFIX@ -- Configuring incomplete, errors occurred! See also "/home/abc/catkin_ws/build_isolated/px4/devel/CMakeFiles/CMakeOutput.log". See also "/home/abc/catkin_ws/build_isolated/px4/devel/CMakeFiles/CMakeError.log". <== Failed to process package 'px4': Command '['/home/abc/catkin_ws/devel_isolated/mavros_px4_launch/env.sh', 'cmake', '/home/abc/catkin_ws/src/PX4-Autopilot', '-DCMAKE_INSTALL_PREFIX=/home/abc/catkin_ws/devel_isolated/px4', '-DCMAKE_MODULE_PATH=/usr/share/cmake/Modules', '-G', 'Unix Makefiles']' returned non-zero exit status 1. Reproduce this error by running: ==> cd /home/abc/catkin_ws/build_isolated/px4 && /home/abc/catkin_ws/devel_isolated/mavros_px4_launch/env.sh cmake /home/abc/catkin_ws/src/PX4-Autopilot -DCMAKE_INSTALL_PREFIX=/home/abc/catkin_ws/devel_isolated/px4 -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules -G 'Unix Makefiles' Command failed, exiting.
07-19
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-3.0.xsd"> <bean id="user1" class="com.unit16.entity.User"> <property name="id" value="1"/> <property name="name" value="张三"/> <property name="password" value="abc"/> <property name="age" value="18"/> </bean> </beans> package com.unit16.test; import com.unit16.entity.User; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test1 { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("springConfig.xml"); String id = context.getId(); } } package com.unit16.entity; import java.io.Serializable; import java.util.List; public class User implements Serializable { private int id; private String name; private String password; private int age; //一对一关系,用户和身份证关系 private IdCard idCard; //一对多关系,用户-订单 private List<Order> orders; //多对多关系,用户-角色 private List<Role> roles; public User(){ } public User(int id, String name, String password,int age) { this.id = id; this.name = name; this.password = password; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public IdCard getIdCard() { return idCard; } public void setIdCard(IdCard idCard) { this.idCard = idCard; } public List<Order> getOrders() { return orders; } public void setOrders(List<Order> orders) { this.orders = orders; } public List<Role> getRoles() { return roles; } public void setRoles(List<Role> roles) { this.roles = roles; } } <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <!-- 上面部分:文件的XML声明和命名空间定义部分,它定义了文件的基本结构和遵循的规范,固定写上即可 --> <!-- 基础信息:当前项目的相关信息,如果该项目被其他项目依赖,要用到的内容 --> <modelVersion>4.0.0</modelVersion> <!--件的元数据标识,用于指定当前 POM 文件遵循的 Maven 版本规范 --> <groupId>com.example</groupId> <!-- 组织 --> <artifactId>unit16</artifactId> <!-- 项目标识 --> <version>1.0.0</version> <!-- 版本号 --> <packaging>jar</packaging> <!-- 可选:war/jar/zip --> <name>unit16</name> <!-- 项目名 --> <description>spring</description> <!-- 项目描述 --> <!-- 依赖管理:配置依赖(jar包) --> <dependencies> <!-- mysql 连接--> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>9.3.0</version> </dependency> <!-- Servlet API--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> <!-- gson--> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.10.1</version> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>7.0.0-M9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>7.0.0-M9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>7.0.0-M9</version> </dependency> <!-- AoP支持 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.3.29</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.7</version> </dependency> <!-- Spring JDBC --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.3.10</version> </dependency> <!-- MyBatis + Spring 整合 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>2.0.6</version> </dependency> </dependencies> </project>版本是Java25,project struct有两个文件,一个是untitled5 untitled18,请分析无法找到getBean方法的原因并给出相应的解决方案
10-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值