Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does java SPI define an interface

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of java SPI how to define the interface, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to define the interface in java SPI. Let's take a look.

instructions

After the service provider provides the specific implementation of the interface, create a file named with the fully qualified name of the interface in the META-INF/services directory of the jar package, which is the fully qualified name of the implementation class.

1. The jar package of the interface implementation class is placed in the classpath of the main program. The main program dynamically loads the implementation module through java.util.ServiceLoder, finds the fully qualified name of the implementation class by scanning the configuration file in the META-INF/services directory, and loads the class into JVM.

2. The implementation class of SPI must carry a structure method without parameters.

Example

Public interface IShout {void shout ();} public class Cat implements IShout {@ Override public void shout () {System.out.println ("miao miao");}} public class Dog implements IShout {@ Override public void shout () {System.out.println ("wang wang");}} this is the end of the article on "how java SPI defines interfaces". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to define the interface of java SPI". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report