Java工具类中Add a private constructor to hide the implicit public one.

问题

Java工具类中出现如下警告:

Add a private constructor to hide the implicit public one.

原因

主要是Java工具类中没有私有无参构造器。

解决

这使用Lombok的工具类注解解决即可:

@UtilityClass
public class FileUtils {

    // public static methods
}

参考

``` public class EmailUtil { public static boolean isEmail(String email) { String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"; Boolean b = email.matches(EMAIL_REGEX); return b; } public static JSONObject sendMail(MyEmailModel emailModel) { JSONObject retMsg = new JSONObject(); // 邮件发送人 String from = emailModel.getEmailAccount(); // 邮件接收人的邮件地址 String to = emailModel.getEmailToUsers(); //定义Properties对象,设置环境信息 Properties props = System.getProperties(); // 设置邮件服务器的地址 // 指定的smtp服务器 props.setProperty("mail.smtp.host", emailModel.getEmailSmtpHost()); props.setProperty("mail.smtp.auth", "true"); //ssl安全链接 props.setProperty("mail.smtp.ssl.enable", emailModel.getEmailSsl()); //设置发送邮件使用的协议 props.setProperty("mail.transport.protocol", "smtp"); if ("587".equals(emailModel.getEmailSmtpPort())) { props.put("mail.smtp.starttls.enable", "true"); } //创建Session对象,session对象表示整个邮件的环境信息 Session session = Session.getInstance(props); //设置输出调试信息 session.setDebug(true); try { // Message的实例对象表示一封电子邮件 MimeMessage message = new MimeMessage(session); // 设置发件人的地址 message.setFrom(new InternetAddress(from, emailModel.getEmailSenderName(), "UTF-8")); // 设置收件人信息 InternetAddress[] sendTo = InternetAddress.parse(to); message.setRecipients(MimeMessage.RecipientType.TO, sendTo); // 设置主题 message.setSubject(emailModel.getEmailTitle()); // 设置邮件的文本内容 message.setContent((emailModel.getEmailContent()), "text/html;charset=utf-8"); // 设置附件 //message.setDataHandler(dh); // 获取发送邮件的对象 Transport transport = session.getTransport(); // 连接邮件服务器 transport.connect(emailModel.getEmailSmtpHost(), Integer.parseInt(emailModel.getEmailSmtpPort()), emailModel.getEmailAccount(), emailModel.getEmailPassword()); // 发送消息 transport.sendMessage(message, sendTo); transport.close(); retMsg.put("code", true); retMsg.put("error", ""); return retMsg; } catch (MessagingException | UnsupportedEncodingException e) { retMsg.put("code", false); retMsg.put("error", e.toString()); return retMsg; } } }```Add a private constructor to hide the implicit public one. “\w-_\.” Remove duplicates in this character class. Refactor this repetition that can lead to a stack overflow for large inputs. This block of commented-out lines of code should be removed.
最新发布
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值