Help us understand the problem. What is going on with this article?

プレミアムフライデーを求める記述をKotlinで書いてみた

More than 3 years have passed since last update.

これは何?

プレミアムフライデーを求めるメソッドを作った(Java8版) - QiitaのコードをKotlinで書いてみたもの。

コード

import java.time.*
import java.time.Month.*
import java.time.format.DateTimeFormatter
import java.time.temporal.TemporalAdjusters

object PremiumFridayKotlin {

    @JvmStatic fun main(args: Array<String>) {

        val years = intArrayOf(2017, 2018, 2019, 2020)
        for (year in years) values()
                    .filterNot { year == 2017 && it == JANUARY }
                    .map { YearMonth.of(year, it) }
                    .map { getMonthOfPremiumFriday(it) }
                    .forEach { println(DateTimeFormatter.ofPattern("yyyy/MM/dd(E)").format(it)) }
    }

    private fun getMonthOfPremiumFriday(ym: YearMonth): LocalDate {

        val premiumFriday = ym.atEndOfMonth().with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY))

        return premiumFriday

    }


}

すごーい、わかりやすい!

注意

あくまでも趣旨はプレミアムフライデーの日付を返すことなので、別のメソッドにしています。

懺悔

Kotlin全く書けないマンなので、IntelliJ IDEA the Java IDE を使ってJavaのコードをKotlinに変換してもらっただけです。

このコードはインチキだ!などとクレーム付けないでください。
こう書けるよ、という指摘は勉強になるのでお願いします。

何が言いたいかというと

Kotlin1.1のリリース、おめでとうございます

Kotlin 1.1 リリース – JavaScriptサポート、コルーチン(coroutine)等々 | JetBrains ブログ

IntelliJ IDEAは素晴らしいツール!

業務で使う機会あるかなぁ

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした