observable_Java Observable countObservers()方法与示例
observable
可观察的类countObservers()方法 (Observable Class countObservers() method)
countObservers() method is available in java.util package.
countObservers()方法在java.util包中可用。
countObservers() method is used to count the number of observers exists in this Observable.
countObservers()方法用于计算此Observable中存在的观察者的数量。
countObservers() 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.
countObservers()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。
countObservers() method does not throw an exception at the time of counting the observer.
在计数观察者时, countObservers()方法不会引发异常。
Syntax:
句法:
public int countObservers();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is int, it gets the number of observers in this Observable.
方法的返回类型为int ,它获取此Observable中的观察者数量。
Example:
例:
// Java program to demonstrate the example
// of int countObservers() 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 countObs() {setChanged();
// By using notifyObservers() method is
// to notify all the observers that are
// implemented
notifyObservers();
}
}
public class CountObservers {// 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.countObs();
}
}
Output
输出量
observed.countObservers(): 2
Obs2:
Obs1:
翻译自: https://www.includehelp.com/java/observable-countobservers-method-with-example.aspx
observable
observable_Java Observable countObservers()方法与示例相关推荐
- .net连接mysql数据_.net连接MYSQL数据库的方法及示例!
连接MYSQL数据库的方法及示例 方法一: 使用MYSQL推出的MySQL Connector/Net is an ADO.NET driver for MySQL 该组件为MYSQL为ADO.NET ...
- set.difference() 的用法(python3)_Python 集合 difference_update() 使用方法及示例
Python 集合 difference_update() 使用方法及示例 Difference_update()使用集合的差集更新集合,并调用difference_update()方法. 如果A和B ...
- doc python 颜色_Python wordcloud.ImageColorGenerator方法代码示例
本文整理汇总了Python中wordcloud.ImageColorGenerator方法的典型用法代码示例.如果您正苦于以下问题:Python wordcloud.ImageColorGenerat ...
- isdigit函数在C语言什么意思,C 库函数 isdigit() 使用方法及示例
C 库函数 isdigit() 使用方法及示例 isdigit()函数检查字符是否为数字字符(0-9). isdigit()的函数原型int isdigit( int arg ); 函数isdigit ...
- python中append的用法_Python 列表 append() 使用方法及示例
Python 列表 append() 使用方法及示例 append()方法将一个项目添加到列表的末尾. append()方法将单个项目添加到列表的末尾. append()方法的语法为:list.app ...
- java kryo_Kryo框架使用方法代码示例
Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...
- python文件的用法,Python 文件 readlines() 使用方法及示例
Python 文件 readlines() 使用方法及示例 概述 readlines() 方法用于读取所有行(直到结束符 EOF)并返回列表,该列表可以由 Python 的 for... in ... ...
- php一些单选、复选框的默认选择方法(示例)
转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...
- java math round小数_Java Math round() 使用方法及示例
Java Math round() 使用方法及示例 Java Math round()方法将指定的值四舍五入为最接近的int或long值,然后将其返回. 也就是说,1.2四舍五入为1,1.8四舍五入为 ...
最新文章
- python的类的super()
- 基于PHP的图片共享网站设计,基于php实现的web图片共享系统(论文+程序)
- 科大星云诗社动态20210318
- 读取不同位置的配置文件
- 信息学奥赛一本通C++语言——1105:数组逆序重存放
- 存储与硬盘挂载 200305
- mybatis-generator 详细配置及使用,爬坑记录
- thinkPHP 模板中的语法
- Java:键盘输入一个小数,输出其整数部分
- 详解:MapReduce 思想解析
- R语言中rvest包爬虫代码+示例讲解(爬取当当网)
- python乌龟吃鱼_关于乌龟吃鱼游戏的问题
- vb.net 教程 5-19 拓展:制作一个QQ大家来找茬和美女找茬辅助工具
- Mac CAD2018 安装完成后,打开注册机时出现 应用程序“02_注册机”不能打开。
- mfc chartctrl 饼状图编写_南瓜糯米饼:外酥里糯,吃到嘴巴里,真是舌尖上的享受...
- 关于DE405星历表的调用
- 微信支付-扫码支付方式在ThinkPHP商城中的使用(第二部分)
- gitweb 搭建教程
- 基于OpenSfM的单目三维重建实现详细步骤
- 黑群晖6.x安装教程