observable_Java Observable deleteObserver()方法与示例

observable

可观察的类deleteObserver()方法 (Observable Class deleteObserver() method)

  • deleteObserver() method is available in java.util package.

    deleteObserver()方法在java.util包中可用。

  • deleteObserver() method is used to remove the given observer (obs) from the set of observers of this Observable object.

    deleteObserver()方法用于从此Observable对象的观察者集中删除给定的观察者。

  • deleteObserver() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    deleteObserver()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • deleteObserver() method does not throw an exception at the time of deleting an observer.

    deleteObserver()方法在删除观察者时不会引发异常。

Syntax:

句法:

    public void deleteObserver(Observer obs);

Parameter(s):

参数:

  • Observer obs – represents the observer to be removed from the set.

    Observer obs –代表要从集合中删除的观察者。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example 
// of void deleteObserver(Observer obs) method of Observable
import java.util.*;
// Implement Observers class 
class Observers_1 implements Observer {
public void update(Observable obj, Object ob) {
System.out.println("Obs1: ");
}
}
class Observers_2 implements Observer {
public void update(Observable obj, Object ob) {
System.out.println("Obs2: ");
}
}
// Implement Observed Class
class Observed extends Observable {
// Function call
void deleteObs() {
setChanged();
// By using notifyObservers() method is 
// to notify all the observers that are
// implemented
notifyObservers();
}
}
public class DeleteObservers {
// Implement Main Method
public static void main(String args[]) {
Observed observed = new Observed();
Observers_1 obs1 = new Observers_1();
Observers_2 obs2 = new Observers_2();
observed.addObserver(obs1);
observed.addObserver(obs2);
// By using countObservers() method is
// to return the number of observers 
// in this object
int count_obs = observed.countObservers();
System.out.println("observed.countObservers(): " + count_obs);
observed.deleteObs();
// By using deleteObserver() method is used
// delete the given observer if exists
observed.deleteObserver(obs2);
count_obs = observed.countObservers();
System.out.println("observed.deleteObserver(obs2): " + count_obs);
observed.deleteObs();
}
}

Output

输出量

observed.countObservers(): 2
Obs2: 
Obs1: 
observed.deleteObserver(obs2): 1
Obs1: 

翻译自: https://www.includehelp.com/java/observable-deleteobserver-method-with-example.aspx

observable

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545202.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

偶尔所得代码片(进程和锁相关)

--杀死相关进程&#xff08;必须要用dba账号sys&#xff09; --alter system kill session session_id, serial#;alter system kill session 500,2568;--select lower(CHR(64ROWNUM)) from dual connect by ROWNUM <126--查进程 select * from v$process; --查锁 select * f…

熬夜都要看完的 Spring 干货!

在 Java 后端框架繁荣的今天&#xff0c;Spring 无疑是最最最火热&#xff0c;也是必不可少的开源框架&#xff0c;像腾讯、阿里、字节跳动等一线互联网公司都选择 Spring 作为基础的开发框架。而 Spring 生态圈里最让人兴奋的莫过于 Spring Boot 框架。他简化了使用 Spring 的…

2014值得期待的Erlang两本新书

在2014年的开头就有这样一个令人振奋的好消息,Erlang有一本新书即将出版 《The Erlang Runtime System》,其作者happi在2013年3月份发布了这本书的写作计划:"The plan is to have the book done by the end of 2013 and published early 2014. ",出版方是O’Reilly,依…

页面分栏LayoutInflater

/* 页面分栏*/ public class TabDemo extends TabActivity {/** Called when the activity is first created. */Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);TabHost tabHost getTabHost();LayoutInflater.from(this).inf…

这么简单的三目运算符,竟然这么多坑?

最近在一个业务改造中&#xff0c;使用三目运算符重构了业务代码&#xff0c;没想到测试的时候竟然发生 NPE 的问题。重构代码非常简单&#xff0c;代码如下&#xff1a;// 方法返回参数类型为 Integer // private Integer code; SimpleObj simpleObj new SimpleObj(); // 其…

Java 邮箱判断 正则表达式

import java.util.Scanner;public final class EmailCheck {public static boolean checkEmail(String email){String regex1 "[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9][.][a-zA-Z0-9]";//字母开头&#xff0c;后加字母或数字&#xff0c;后面加点&#xff0c;后面字母或数…

Java DataInputStream skipBytes()方法与示例

DataInputStream类skipBytes()方法 (DataInputStream Class skipBytes() method) skipBytes() method is available in java.io package. skipBytes()方法在java.io包中可用。 skipBytes() method is used to skip the given number of bytes of data from this DataInputStrea…

nagios客户端nrped服务方式启动脚本

1、平时配置nagios客户端nrped启动最常用的就是在/etc/rc.local文件配置&#xff1a;/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d2、但是还有更好的方式&#xff08;这样方便使用脚本启动或者关闭&#xff09;&#xff1a;在/etc/init.d目录下创建nrped脚…

用好MySQL的21个好习惯!

前言每一个好习惯都是一笔财富&#xff0c;本文分SQL后悔药&#xff0c; SQL性能优化&#xff0c;SQL规范优雅三个方向&#xff0c;分享写SQL的21个好习惯&#xff0c;谢谢阅读&#xff0c;加油哈~1. 写完SQL先explain查看执行计划&#xff08;SQL性能优化&#xff09;日常开发…

第四章图像增强

第四章图像增强1_图像增强的概念2_空间域增强2.1_图像增强的点运算2.1.1_灰度变换2.1.2_直方图均衡化2.1.3 直方图规定化1_图像增强的概念 什么是图像增强&#xff1a;图像增强是采用一系列技术去改善图像的视觉效果,或将图像转换成一种更适合于人或机器进行分析和处理的形式。…

Java DataInputStream readShort()方法(带示例)

DataInputStream类readShort()方法 (DataInputStream Class readShort() method) readShort() method is available in java.io package. readShort()方法在java.io包中可用。 readShort() method is used to read 2 bytes (i.e. 16 bit) of data input and returns a short va…

IP 对应 网址

IP 对应 网址 /* 网址和IP对应的小例子 */try {InetAddress address_1 InetAddress.getByName("www.baidu.com");InetAddress address_2 InetAddress.getByName("10.2.8.13");System.out.println(address_1.toString());System.out.println(address_2.t…

springboot发送qq邮件

springboot发送qq邮件1_开启邮箱相关权限并获取邮箱授权码2_实现功能2.1_添加mail的依赖2.1.1_创建工程时添加2.1.2_在工程中添加2.2_配置文件application.properties配置相关信息2.3_实现代码1_开启邮箱相关权限并获取邮箱授权码 进入账户 开启POP3/SMTP服务并生成授权码 …

反转链表-剑指offer-16

题目&#xff1a;定义一个函数&#xff0c;输入一个链表的头节点&#xff0c;反转该链表并输出反转后链表的头节点。分析&#xff1a;逐个头插&#xff0c;实现反转设置3个指针&#xff1a;head 头节点、prev 前一个节点、 cur 下一个节点注意&#xff1a;链表为空&#xff0c;…

getsimplename_Java类类getSimpleName()方法的示例

getsimplename类类getSimpleName()方法 (Class class getSimpleName() method) getSimpleName() method is available in java.lang package. getSimpleName()方法在java.lang包中可用。 getSimpleName() method is used to return the simple name of the underlying class as…

MyEclipse编码设置,中文乱码解决方法,UTF-8,GBK

在Myeclipse导入一个项目&#xff0c;有中文乱码问题&#xff0c;解决方法如下&#xff1a;一、将整个project设置编码UTF-8&#xff08;UTF-8可以最大的支持国际化&#xff09; windows->Preferences->general->Workspace->Text file encoding->Other框中的Tex…

Spring Cloud Alibaba 深度解密!

说说吧&#xff0c;程序猿们&#xff0c;你们还有谁不是“单身G”&#xff1f;想要“赢取”白富美&#xff0c;当上CTO&#xff0c;走上人生巅峰&#xff0c;不努力怎么可以&#xff1f;别人疯狂购物&#xff0c;你疯狂学习&#xff0c;努力30天&#xff0c;向阿里P6迈进&#…

安卓连接真机调试

安卓连接真机调试一、打开开发者模式二、打开USB调试三、最后连接数据线这里使用荣耀20pro为例一、打开开发者模式 点击版本号&#xff0c;多点几下直到打开开发者模式 二、打开USB调试 系统与更新——>开发人员选项 三、最后连接数据线 连接数据线并选择MIDI模式

Java ByteArrayInputStream skip()方法与示例

ByteArrayInputStream类skip()方法 (ByteArrayInputStream Class skip() method) skip() method is available in java.util package. skip()方法在java.util包中可用。 skip() method is used to skip the given number of bytes (no_of_bytes) from this stream. skip()方法用…

3W字!带你玩转「消息队列」

1. 消息队列解决了什么问题消息中间件是目前比较流行的一个中间件&#xff0c;其中RabbitMQ更是占有一定的市场份额&#xff0c;主要用来做异步处理、应用解耦、流量削峰、日志处理等等方面。1. 异步处理一个用户登陆网址注册&#xff0c;然后系统发短信跟邮件告知注册成功&…